在工作单元克隆em.merge中遇到空或零主键

时间:2014-04-08 21:32:06

标签: java-ee jpa ejb

我该如何解决这个问题?我不明白这个错误!

例外:

    Caused by: javax.persistence.RollbackException: Exception [EclipseLink-7197] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Null or zero primary key encountered in unit of work clone [Entities.Employe[ matEmp=0 ]], primary key [0]. 

这是我的代码:

EntityTransaction et = em.getTransaction();
et.begin();
Employe e = em.find(Employe.class,mat);
e.setNp(np);
em.merge(e);

1 个答案:

答案 0 :(得分:3)

EclipseLink似乎不喜欢0作为主键。

您可以在persistence.xml中指定为here