org.eclipse.persistence.exceptions.QueryException: The primary key read from the row during the execution of the query was detected to be null

What database are you using, and what does it return for the column names?

EclipseLink is case sensitive in less recent versions by default unless the eclipselink.jpa.uppercase-column-names persistent property is set to true.

This might be the problem for native queries if the database returns the column name as uppercase "ID" when you have it defined as lowercase "id".

Try changing the column definitions in the annotations to match what your database uses or adding the property with a value of true.


The problem is that eclipselink is case sensitive. There is a "hint" available that will address this. Place the following between your properties element in the persistence.xml file:

<!-- Hint to solve "The primary key read from the row [DatabaseRecord(...)] during the execution of the query was detected to be null." errors.-->
<property name="eclipselink.jpa.uppercase-column-names" value="true"/>

That will treate the column names in a case insensitive manner and eliminate the error.


Found this thread https://forums.oracle.com/thread/614380.

Had the same issue with postgres and EclipseLink.

Solution: Change the primary key column to be upper case that is:

select id as "ID", field1, field2,..., fieldn from table ....