1

I am facing a common but irritating problem in eclipseLink. I am just trying to run this query using eclipseLink:

List organizationUnitEntityList = entityManager.createQuery("select o from OrganizationUnitEntity o where o.unitId=?1").setParameter(1, userTypeDomain.getUnitId()).getResultList(); OrganizationUnitEntity organizationUnitEntity = organizationUnitEntityList.get(0);

// 1 is passed as parameter

OrganizationUnitEntity is :

public class OrganizationUnitEntity {

@Id
private int unitId;
private String unit;

    getters and setters...

}

But the exception that I am getting is : Null or zero primary key encountered in unit of work clone

Now, as there is no null or 0 primary key in the database, why this one is coming??

4

1 回答 1

0

异常发生在哪里 - 您提到您正在执行查询,但它是否在执行查询之前尝试刷新?您可以尝试在查询之前调用 flush ,因为您的 EM 可能包含一个具有 0/null pk 的实体,而它不应该。如果它发生在查询之后,请检查查询中的 SQL 将返回什么结果。尝试将 EclipseLink 日志记录设置为最好:如果您仍然无法使用以下内容打印缓存中的内容: JPAHelper.getEntityManager(em).getActiveSession().getIdentityMapAccessor().printIdentityMaps();

于 2012-04-09T13:56:39.143 回答