Showing posts with label EclipseLink. Show all posts
Showing posts with label EclipseLink. Show all posts

Sunday, November 6, 2011

EclipseLink: Null primary key encountered in unit of work clone

I came across this weird issue while using EclipseLink 2.0 with JPA 2.0. It isn't actually that complicated as it looks. Though I spent lot of time figuring out whether any objects have null id or negative id. Finally figured out that, The database had rows with id as '0'. By default EclipseLink treats zero ids as null. I don't


Simple fix is to tell EclipseLink to treat '0' as a valid id and not null. It can be done by specifying the property in persistence.xml 


In persistence.xml add the following property to get rid of this exception. 


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


This property simply tells EclipseLink to treat '0' as a valid primary key instead of null.