简体   繁体   English

Java实体错误-主键为空

[英]Java Entity error - null primary key

I have 2 entity classes: Shipvia and Route. 我有2个实体类:Shipvia和Route。 My Shipvia is working fine. 我的Shipvia工作正常。 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 我在Shipvia上的工作实体类在这里: http ://pastebin.com/R53tNHyp

My entity class for Route is: http://pastebin.com/8f4L2Z62 我对Route的实体类是: 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. 除非我因缺少变量或字段而在某个地方犯了错误,否则我不确定在尝试从上述方法获取resultList时为什么会收到以下错误。

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! 我不确定从哪里开始寻找错误!

我相信这个SQL会解决它

delete from ROUTE where ROUTEKEY is null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM