Search code examples
jakarta-eejpaejb

Null or zero primary key encountered in unit of work clone em.merge


How can I solve this problem? I don't understand the error!

The Exception:

    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]. 

Here is my Code:

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

Solution

  • EclipseLink does not seem to like 0 as primary key.

    You can specify that in persistence.xmlas desribed here.