title: JPA find() does not load Entity @Id
body: <p>I'm starting to use JPA with the OpenJPA API, and i'm having a problem with the find().
  Here are the tables:</p>
  
  <pre><code>CREATE TABLE compania (
    ID int(11) NOT NULL,
    NOMBRE varchar(45) DEFAULT NULL,
    PRIMARY KEY (ID)
  ) 
  
  CREATE TABLE modelo (
    ID int(11) NOT NULL,
    ID_COMPANIA int(11) DEFAULT NULL,
    NOMBRE_MODELO varchar(45) DEFAULT NULL,
    PRIMARY KEY (ID),
    KEY MODELO_COMPANIA_FK_idx (ID_COMPANIA),
    CONSTRAINT MODELO_COMPANIA_FK FOREIGN KEY (ID_COMPANIA) REFERENCES compania (ID)
  ) 
  </code></pre>
  
  <p>and here are my Entities:</p>
  
  <pre><code>@Entity
  public class Compania extends EntityJPA{
  
      private static final long serialVersionUID = 1L; 
  
      @Id
      private int id;
  
      @Column
      private String nombre;
  
      @OneToMany(mappedBy="compania",cascade={CascadeType.ALL})
      @JoinColumn(name="ID_COMPANIA", nullable=false)
      private List&lt;Modelo&gt; listaModelos;
  
      public Compania() {
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int idCompania) {
          this.id = idCompania;
      }
  
      public String getNombre() {
          return nombre;
      }
  
      public void setNombre(String nombreCompania) {
          this.nombre = nombreCompania;
      }
  
      public List&lt;Modelo&gt; getListaModelos() {
          return listaModelos;
      }
  
      public void setListaModelos(List&lt;Modelo&gt; listaModelos) {
          this.listaModelos = listaModelos;
      }
  }
  
  @Entity
  public class Modelo extends EntityJPA{
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private int id;
  
      @Column(name="NOMBRE_MODELO")
      private String nombreModelo;
  
      @ManyToOne
      @JoinColumn(name="ID_COMPANIA", referencedColumnName="ID")
      private Compania compania;
  
      public Modelo() {
      }
  
      public Compania getCompania() {
          return compania;
      }
  
      public void setCompania(Compania compania) {
          this.compania = compania;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int idModelo) {
          this.id = idModelo;
      }
  
      public String getNombre() {
          return nombreModelo;
      }
  
      public void setNombre(String nombreModelo) {
          this.nombreModelo = nombreModelo;
      }
  }
  </code></pre>
  
  <p>At the moment I make the </p>
  
  <pre><code>Compania cia = getEntityManager().find(Compania.class, idCompania);
  </code></pre>
  
  <p>the cia object does not have the value of the @Id attribute, it has the value of nombre but not of id. I mean:</p>
  
  <pre><code>cia.getId() = 0
  </code></pre>
  
  <p>and it must be 1 or 2 , etc. Not 0.</p>
  
  <p>Thank you very much for your help.</p>
  
  <p>I do not have the code to persist because It was already persisted.
  the code for the find is</p>
  
  <pre><code>public static Compania findCompania(int idCompania){
          try {
              Compania cia = getEntityManager().find(Compania.class, idCompania);
              return cia;
          } finally {
              closeEntityManager();
          }
      }
  </code></pre>
  
  <p>And if I activate the log, this is the select it shows:</p>
  
  <pre><code>482  testMySql  TRACE  [http-bio-8080-exec-5] openjpa.jdbc.SQL - &lt;t 1228180882, conn 1699837157&gt; executing prepstmnt 2127861376 SELECT t0.nombre FROM Compania t0 WHERE t0.id = ? [params=(int) 1]
  497  testMySql  TRACE  [http-bio-8080-exec-5] openjpa.jdbc.SQL - &lt;t 1228180882, conn 1699837157&gt; [15 ms] spent
  </code></pre>
  
  <p>As you can see, there is no t0.id in the select.</p>
  
  <p>Thanks for your help.</p>