in EclipseLink, JPA

EclipseLink error : Null primary key encountered in unit of work clone

With EclipseLink used as the JPA provider, the following error message “Null primary key encountered in unit of work clone” may appear if the value 0 is used for a field which is a primary key.

To resolve it, a few solutions :

1) start your primary key values from 1 instead of 0, which in my opinion is the best solution.

2) add the following annotation to the entity :

import javax.persistence.Entity;
import javax.persistence.Table;

import org.eclipse.persistence.annotations.IdValidation;
import org.eclipse.persistence.annotations.PrimaryKey;

 * The persistent class for the HOUSE database table.
@Table(name = "HOUSE")
public class House implements Serializable {



3) add the following property to the persistence.xml file :

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi=""
	xmlns="" version="2.0">

	<persistence-unit name="myUnit">

                    <property name="eclipselink.allow-zero-id" value="true"/> 



Links :