我有2个实体类:Shipvia和Route。我的Shipvia工作正常。 Route实体类是它的精确副本,但当然是为表名和字段量身定制的。使用此方法读取这两个类:
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;
}
}
我的Shipvia工作实体课在这里:http://pastebin.com/R53tNHyp
我的Route实体类是:http://pastebin.com/8f4L2Z62
除非我因错过变量或字段而在某处犯了错误,否则我不确定为什么在尝试从上述方法中获取resultList时会出现以下错误。
我收到以下错误:
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")
如果我运行上面的查询
,那有多奇怪SELECT ROUTEKEY, RUADD_DATE, RUADD_TERM, RUADD_TIME, RUADD_USER, RUCHG_DATE, RUCHG_NUMB, RUCHG_TERM, RUCHG_TIME, RUCHG_USER, ROUTE FROM ROUTE
它返回一个完美的结果。我不知道从哪里开始寻找错误!
答案 0 :(得分:1)
我相信这个sql会解决它
delete from ROUTE where ROUTEKEY is null