1

我有 2 个实体类:Shipvia 和 Route。我的 Shipvia 工作正常。路由实体类是它的精确副本,但当然是为表名和字段量身定制的。使用此方法读取两个类:

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

它返回一个完美的结果。我不确定从哪里开始寻找错误!

4

1 回答 1

1

我相信这个sql会解决它

delete from ROUTE where ROUTEKEY is null
于 2012-05-28T17:01:22.360 回答