title: org.hibernate.AnnotationException:No identifier specified for entity with XML Mapping
body: <p>I'm working on a JPA program and had to write annotations for one class via xml-mapping. I wrote my model class like that:</p>
  
  <pre class="lang-java prettyprint-override"><code>ppackage model;
  
  import javax.persistence.*;
  import java.util.Date;
  public class Reservierung {
      public Reservierung(Date datum, int praemienMeilenBonus, int preis, StatusInfo status, Zug zug, Strecke strecke, Benutzer benutzer, Zahlung zahlung) {
          this.datum = datum;
          this.praemienMeilenBonus = praemienMeilenBonus;
          this.preis = preis;
          this.status = status;
          this.zug = zug;
          this.strecke = strecke;
          this.benutzer = benutzer;
          this.zahlung = zahlung;
      }
  
      private Long ID;
  
      private Date datum;
  
      private int praemienMeilenBonus = 15;
  
      private int preis = 150;
  
      private StatusInfo status;
      private Zug zug;
      private Strecke strecke;
      private Benutzer benutzer;
      private Zahlung zahlung;
  
      public Date getDatum() {
          return datum;
      }
  
      public void setDatum(Date datum) {
          this.datum = datum;
      }
  
      public int getPraemienMeilenBonus() {
          return praemienMeilenBonus;
      }
  
      public void setPraemienMeilenBonus(int praemienMeilenBonus) {
          this.praemienMeilenBonus = praemienMeilenBonus;
      }
  
      public int getPreis() {
          return preis;
      }
  
      public void setPreis(int preis) {
          this.preis = preis;
      }
  
      public StatusInfo getStatus() {
          return status;
      }
  
      public void setStatus(StatusInfo status) {
          this.status = status;
      }
  
      public Zug getZug() {
          return zug;
      }
  
      public void setZug(Zug zug) {
          this.zug = zug;
      }
  
      public Strecke getStrecke() {
          return strecke;
      }
  
      public void setStrecke(Strecke strecke) {
          this.strecke = strecke;
      }
  
      public Benutzer getBenutzer() {
          return benutzer;
      }
  
      public void setBenutzer(Benutzer benutzer) {
          this.benutzer = benutzer;
      }
  
      public Zahlung getZahlung() {
          return zahlung;
      }
  
      public void setZahlung(Zahlung zahlung) {
          this.zahlung = zahlung;
      }
  
      public Long getID() {
          return ID;
      }
  
      public void setID(Long ID) {
          this.ID = ID;
      }
  }
  </code></pre>
  
  <p>and after that I created the xml mapping file that I named orm:</p>
  
  <pre class="lang-xml prettyprint-override"><code>
  ?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
          version="2.0"&gt;
      &lt;named-query name="Reservierung.findAll"&gt;
          &lt;query&gt;SELECT b FROM model.Reservierung b&lt;/query&gt;
      &lt;/named-query&gt;
      &lt;entity name="Reservierung" class="model.Reservierung" &gt;
          &lt;table name="Reservierung" /&gt;
          &lt;attributes&gt;
              &lt;id name="ID"&gt;
                  &lt;generated-value strategy="AUTO" /&gt;
              &lt;/id&gt;
              &lt;basic name="datum" /&gt;
              &lt;basic name="praemienMeilenBonus" /&gt;
              &lt;basic name="preis" /&gt;
              &lt;basic name="StatusInfo" /&gt;
  
              &lt;one-to-one name="strecke" /&gt;
              &lt;one-to-one name="zug"/&gt;
              &lt;one-to-one name="benutzer"/&gt;
              &lt;transient name="zahlung"/&gt;
          &lt;/attributes&gt;
      &lt;/entity&gt;
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p>finnaly I added the orm.xml and all the other files in my persistence.xml, which looks now like this</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
               http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
    version="2.1"&gt;
  
    &lt;persistence-unit name="westbahn"&gt;
        &lt;description&gt; Hibernate JPA Configuration Example&lt;/description&gt;
        &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
  
        &lt;mapping-file&gt;META-INF/orm.xml&lt;/mapping-file&gt;
  
        &lt;class&gt;model.Bahnhof&lt;/class&gt;
        &lt;class&gt;model.Benutzer&lt;/class&gt;
        &lt;class&gt;model.Reservierung&lt;/class&gt;
        &lt;class&gt;model.Einzelticket&lt;/class&gt;
        &lt;class&gt;model.Preisstaffelung&lt;/class&gt;
        &lt;class&gt;model.Sonderangebot&lt;/class&gt;
        &lt;class&gt;model.Strecke&lt;/class&gt;
        &lt;class&gt;model.Ticket&lt;/class&gt;
        &lt;class&gt;model.Zeitkarte&lt;/class&gt;
        &lt;class&gt;model.Zug&lt;/class&gt;
        &lt;class&gt;model.Reservierung&lt;/class&gt;
  
          &lt;properties&gt;
      &lt;!--
            &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" /&gt;
            &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/westbahn?serverTimezone=UTC" /&gt;
            &lt;property name="javax.persistence.jdbc.user" value="westbahnUser" /&gt;
            &lt;property name="javax.persistence.jdbc.password" value="westbahnPassword" /&gt;
      --&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /&gt;
              &lt;property name="javax.persistence.jdbc.url"    value="jdbc:h2:file:./db/testing" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="sa" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/&gt;
              &lt;property name="hibernate.show_sql" value="false" /&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
              &lt;!--&lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/&gt;--&gt;
          &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  
  </code></pre>
  
  <p>Till now I tried to see if the names where spelled wrong, if my class had some attributes that I didn't account for and also tried to change the name and finally added access="field" to the entity tag, but if I do so, I get another exception on top of the first one: <strong>org.hibernate.AnnotationException: Unable to load class defined in XML: model.Reservierung</strong></p>
  
  <p>Where did I do wrong?</p>
  
  <p>edit:
  Before the new orm.xml I had different mapping file named  Reservierung.hbm.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>
  &lt;?xml version = "1.0" encoding = "utf-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  
  &lt;hibernate-mapping&gt;
      &lt;class name="model.Reservierung" table="Reservierung"&gt;
          &lt;meta attribute = "class-description"&gt;
              This class contains the reservations
          &lt;/meta&gt;
  
          &lt;id name = "ID" type = "long" column = "ID"&gt;
              &lt;generator class="native"/&gt;
          &lt;/id&gt;
  
          &lt;property name = "datum" column = "datum" type = "date"&gt; &lt;/property&gt;
          &lt;property name = "praemienMeilenBonus" column = "praemienMeilenBonus"&gt; &lt;/property&gt;
          &lt;property name = "preis" column = "preis"&gt; &lt;/property&gt;
          &lt;property name = "status" column = "status"&gt;
              &lt;type name="org.hibernate.type.EnumType"&gt;
                  &lt;param name="enumClass"&gt;model.StatusInfo&lt;/param&gt;
              &lt;/type&gt;
          &lt;/property&gt;
          &lt;one-to-one name="strecke" /&gt;
          &lt;one-to-one name="zug"/&gt;
          &lt;one-to-one name="benutzer"/&gt;
  
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>I wasn't happy with it, so I trashed it and started from scratch with the orm.xml file</p>
  
  <p>edit: what I did:
  I made a constructor + getter and setter in all classes and now the exception changed to this:</p>
  
  <pre class="lang-java prettyprint-override"><code>java.lang.ClassCastException: class org.hibernate.mapping.SingleTableSubclass cannot be cast to class org.hibernate.mapping.RootClass (org.hibernate.mapping.SingleTableSubclass and org.hibernate.mapping.RootClass are in unnamed module of loader 'app')
      at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:214)
      at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:205)
      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2283)
      at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:976)
      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:803)
      at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:254)
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:230)
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:273)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:903)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:934)
      at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:56)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      at main.Main.main(Main.java:47)
  Exception in thread "main" java.lang.NullPointerException
      at main.Main.main(Main.java:64)
  
  </code></pre>