title: What is the difference between "Persistent Class" and "Entity" in JPA or in Hibernate?
body: <p>First things first:</p>
  <ol>
  <li>I'm aware of <a href="https://stackoverflow.com/questions/28372601/what-is-the-difference-between-entity-and-persistent-class">this</a> question, which, at the high level of abstraction, asks same what I ask here; however, I find it (and its answer) lacking, therefore, I would like to elaborate on this topic here;</li>
  <li>I would kindly ask anyone, who has a good understanding of the <em>formal definitions</em> in the JPA and Hibernate, to help me clarify this mess.</li>
  </ol>
  <p>Disclaimer: I am not looking for the basic explanations of what the Entity is and how to use it. I am using Hibernate/JPA for quite some time now.</p>
  <p>My question is more about <em>formal definitions</em>, in order to clarify the distinctions of the formal semantics (definitions) between <em>Entity</em> and <em>Persistent Class</em>, to make it crystal-clear how one differs from another and how they are defined.</p>
  <p>Initially, I expected the answer to be found in <a href="https://download.oracle.com/otn-pub/jcp/persistence-2_2-mrel-spec/JavaPersistence.pdf" rel="nofollow noreferrer">JSR 338: JPA Specification 2.2</a> and <a href="https://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/" rel="nofollow noreferrer">Hibernate 5.0.0 Reference Documentation</a>, but I got quite confused, as I was left with a feeling, that, in this context, both documents are lacking, leaving a big room for these concepts/definitions to overlap and introduce some speculations.</p>
  <hr />
  <h2>Let's start with JSR 338: JPA 2.2 Specification:</h2>
  <p>For some (very strange to me) reason, in this entire specification, keyword phrases &quot;Persistent Object&quot; and &quot;Persistent Class&quot; are not found, to wit, they are found only once and twice respectively:</p>
  <blockquote>
  <ul>
  <li><em>Persistent Object</em> - found in the Javadoc comment, saying nothing interesting (page 221)</li>
  <li><em>Persistent Class</em> - found in the xsd documentation, again, saying nothing much (pages: 378, 529)</li>
  </ul>
  </blockquote>
  <p>and, unfortunately, that is it in this specification, nothing more at all.</p>
  <p>The <em>Entity Class</em>, on the other hand, is defined as follows:</p>
  <blockquote>
  <p>An entity is a lightweight persistent domain object. The primary programming artifact is the entity class. An entity class may make use of auxiliary classes
  that serve as helper classes or that are used to represent the state of the entity.</p>
  </blockquote>
  <p>which, again, I find extremely lacking for the formal specification document, but at least, this says that it is a <em>persistent domain object</em>.</p>
  <p>In the same document, <em>Entity</em> is also defined as a Class (2.1 The Entity Class, page 23).</p>
  <p>Even though this might not seem important, it's quite confusing whether it's defined as a <em>Persistent Object</em> or as a <em>Class</em>.</p>
  <p><strong>My conclusion based on this specification document:</strong></p>
  <ol>
  <li><em>Persistent Class/Object</em> is not defined in the JPA 2.2 Specification at all;</li>
  <li><em>Entity</em> is defined as <em>persistent object</em>, <strong>and(!)</strong>, as a <em>Class</em>, which is really unclear to me;</li>
  </ol>
  <p>In my conceptual understanding, <em>Persistent Object</em>, sounds very much as an object, which is persist<em>able</em> <strong>if(!)</strong> it will be mapped correspondingly; hence, <em>Persistent Class</em> - as a <em>Class</em>, instances of which are possible to get persisted (i.e. they can be stored into database layer, by conforming to POJO concept), if the class is mapped accordingly. I.e. <em>Persistent Class</em> is a persist<em>able</em> class, and it transforms to <em>Entity</em>, if it has its corresponding mapping definition (either with .hbm.xml or JPA annotations).</p>
  <hr />
  <h2>Hibernate 5 Reference Documentation</h2>
  <p>On the other hand, Hibernate <a href="https://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/ch04.html" rel="nofollow noreferrer">defines</a> <em>Persistent Classes</em>, and it does this as follows:</p>
  <blockquote>
  <p>Persistent classes are classes in an application that implement the entities of the business problem (e.g. Customer and Order in an E-commerce application). The term &quot;persistent&quot; here means that the classes are able to be persisted, not that they are in the persistent state.</p>
  </blockquote>
  <p>Am I getting this correct, that <em>Persistent Classes implement the entity</em> means, that my upper understanding is correct, and <em>Persistent Class</em> is just a Java class, which implements the <em>Entity</em> model (without mapping), and in conjunction with its mapping (.hbm.xml or JPA) it becomes an <em>Entity</em>? is <em>Persistent Class + Mapping Definition = Entity</em> correct?</p>
  <hr />
  <p>I would also plug here in some snippets from the <a href="https://www.manning.com/books/java-persistence-with-hibernate-second-edition" rel="nofollow noreferrer">Java Persistence with Hibernate, Second Edition</a> book:</p>
  <blockquote>
  <p>You wrote a persistent class and its mapping with annotations. - (Summary 2.4);</p>
  </blockquote>
  <p><em>kind of, differentiates persistent class from its mapping, and that, again, sort of supports the idea, that persistent class and its mapping are distinct concepts, which logically brings the point, that persistent class alone, is not an Entity.</em></p>
  <blockquote>
  <p>The persistent classes are unaware of—and have no dependency on—the persistence mechanism. - (Chapter 3.2);</p>
  </blockquote>
  <p><em>clearly states, that Persistent Classes are unaware of the persistence mechanism.</em></p>
  <blockquote>
  <p>You can reuse persistent classes outside the context of persistence, in unit tests or in the presentation layer, for example. You can create instances in any runtime environment with the regular Java new operator, preserving testability and reusability. - (Chapter 3.2).</p>
  </blockquote>
  <p><em>also supports the idea, that Persistent Class is not necessarily a mapped Entity.</em></p>
  <p><strong>My conclusion:</strong><br>(based on my initial understanding, which seems to be supported by &quot;Hibernate Reference Documentation&quot; and &quot;Java Persistence with Hibernate, Second Edition&quot; book.)</p>
  <p><em>Persistent Classes</em> are Java classes, which (if needed!) would be conforming with the JPA Specification (according to which, they need to be POJOs and they can be mapped), but they are not Entities if they are not mapped, and they can be used in the outside-of-JPA context, to just operate on them as on ordinary Java objects, or even to present them at the Presentation Layer.</p>
  <hr />
  <h2>Finally:</h2>
  <p>As you can see, my question is a bit of a mixture of different resources, showing my evident confusion, as I cannot clearly define the <em>formal</em>, so called <em>scientifically adopted</em> definitions for these two concepts.</p>
  <p>Can we clearly define what is the <em>Persistent Class</em>, what is <em>Entity</em>, and what is the the <em>semantic</em> and <em>definitive</em> difference/overlapping between them in terms of JPA and Hibernate?</p>