Reputation: 545
I have 2 entity classes: Shipvia and Route. My Shipvia is working fine. Route entity class is an exact copy of it, but of course tailored for the tablename and fields. Both classes are read using this method:
public class RetrieveResultList {
private static final EntityManagerFactory FACTORY = Persistence.createEntityManagerFactory("EntityLibraryPU");
public static <T> List<T> retrieveResultList(Class<T> type) {
EntityManager entityManager = FACTORY.createEntityManager();
String tablename = type.getName(); // figure out table name from **type**
Query query = entityManager.createNamedQuery(tablename + ".findAll");
List<T> resultList = query.getResultList();
entityManager.close();
return resultList;
}
}
My working entity class for Shipvia is here: http://pastebin.com/R53tNHyp
My entity class for Route is: http://pastebin.com/8f4L2Z62
Unless I made a mistake somewhere by missing a variable or field, I am not sure why I get the following error when trying to get the resultList from the above method.
I get the following error:
Local Exception Stack:
Exception [EclipseLink-6044] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [ArrayRecord(
ROUTE.ROUTEKEY => null
ROUTE.RUADD_DATE => null
ROUTE.RUADD_TERM => null
ROUTE.RUADD_TIME => null
ROUTE.RUADD_USER => null
ROUTE.RUCHG_DATE => null
ROUTE.RUCHG_NUMB => null
ROUTE.RUCHG_TERM => null
ROUTE.RUCHG_TIME => null
ROUTE.RUCHG_USER => null
ROUTE.ROUTE => null)] during the execution of the query was detected to be null.
Primary keys must not contain null.
Query: ReadAllQuery(name="Route.findAll" referenceClass=Route sql="SELECT ROUTEKEY, RUADD_DATE, RUADD_TERM, RUADD_TIME, RUADD_USER, RUCHG_DATE, RUCHG_NUMB, RUCHG_TERM, RUCHG_TIME, RUCHG_USER, ROUTE FROM ROUTE")
What's weird is that if I run the query above
SELECT ROUTEKEY, RUADD_DATE, RUADD_TERM, RUADD_TIME, RUADD_USER, RUCHG_DATE, RUCHG_NUMB, RUCHG_TERM, RUCHG_TIME, RUCHG_USER, ROUTE FROM ROUTE
It returns a perfect result. I am not sure where to start looking for an error!
Upvotes: 1
Views: 3584
Reputation: 9162
I believe this sql will solve it
delete from ROUTE where ROUTEKEY is null
Upvotes: 1