title: org.eclipse.persistence.exceptions.QueryException: The primary key read from the row during the execution of the query was detected to be null
body: <p>I'm trying to query some data on JPA, this is my query:</p>
  
  <pre><code>@Override
      public List&lt;HorarioAtencion&gt; findByPeriodo(Person person, int dia, int mes, int anno) {
          Query busqueda = em.createNativeQuery("Select * from HorariosAtencion where " +
                                                "idPerson = ?1 AND "+
                                                "DAY( fechaInicio) &lt;= ?2 AND MONTH( fechaInicio ) &lt;= ?3 AND YEAR( fechaInicio) &lt;= ?4 AND "+
                                                "DAY( fechaFin) &gt;= ?2 AND MONTH( fechaFin ) &gt;= ?3 AND YEAR( fechaFin ) &gt;= ?4 ORDER BY TIME(fechaInicio)", HorarioAtencion.class);
         busqueda.setParameter(1,person.getId());
         busqueda.setParameter(2, dia);
         busqueda.setParameter(3, mes);
         busqueda.setParameter(4, anno);
         return busqueda.getResultList();
      }
  </code></pre>
  
  <p>This query returns results, but the next exception is fired:</p>
  
  <pre><code>Caused by: Exception [EclipseLink-6044] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException
  Exception Description: The primary key read from the row [ArrayRecord(
       =&gt; 1
       =&gt; 13
       =&gt; 2013-01-04 12:25:00.0
       =&gt; 2013-01-04 12:25:00.0
       =&gt; true
       =&gt; true
       =&gt; true
       =&gt; true
       =&gt; true
       =&gt; true
       =&gt; true)] during the execution of the query was detected to be null.  Primary keys must not contain null.
  Query: ReadAllQuery(referenceClass=HorarioAtencion sql="Select * from HorariosAtencion where idPerson = ? AND DAY( fechaInicio) &lt;= ? AND MONTH( fechaInicio ) &lt;= ? AND YEAR( fechaInicio) &lt;= ? AND DAY( fechaFin) &gt;= ? AND MONTH( fechaFin ) &gt;= ? AND YEAR( fechaFin ) &gt;= ? ORDER BY TIME(fechaInicio)")
  </code></pre>
  
  <p>How is this caused and how can I solve it?</p>
  
  <p>Columns definition on entity class:</p>
  
  <pre><code>private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "id")
      private Integer id;
  
      @Basic(optional = false)
      @Column(name = "fechaInicio")
      @Temporal(TemporalType.TIMESTAMP)
      private Date fechaInicio;
  
      @Basic(optional = false)
      @Column(name = "fechaFin")
      @Temporal(TemporalType.TIMESTAMP)
      private Date fechaFin;
  
      @Basic(optional = false)
      @Column(name = "domingo")
      private boolean domingo;
  
      @Basic(optional = false)
      @Column(name = "lunes")
      private boolean lunes;
  
      @Basic(optional = false)
      @Column(name = "martes")
      private boolean martes;
  
      @Basic(optional = false)
      @Column(name = "miercoles")
      private boolean miercoles;
  
      @Basic(optional = false)
      @Column(name = "jueves")
      private boolean jueves;
  
      @Basic(optional = false)
      @Column(name = "viernes")
      private boolean viernes;
  
      @Basic(optional = false)
      @Column(name = "sabado")
      private boolean sabado;
  
      @JoinColumn(name = "idPersona", referencedColumnName = "id")
      @ManyToOne(optional = false)
      private Persona idPersona;
  </code></pre>