persistence@glassfish.java.net

Persisting via cascading

From: Gary Jacobson <gtjacobson_at_gmail.com>
Date: Mon, 23 Nov 2009 16:50:50 +0200

I recently attempted to switch from Toplink Essentials to Eclipselink and
encountered a problem. I have some code which looks like this:

// create new child entity
Child child = new Child();

// add it to the parent entity, which has @OneToMany( cascade =
CascadeType.ALL ) on its childList
child.setParent( parent );
parent.getChildList().add( child );

// now I hand off to a stateless session bean which merges the parent using
em.merge()
parent = myFacade.merge( parent );

// retrieve child id
log( child.getId() );

At this point, using Toplink, I could get the new child's id. However, using
Eclipselink, it returns 0, despite the fact that the child was successfully
created and added to the parent. Is this a bug, or is there some sort of
best practice I'm not using? I'm hoping to avoid using any
Eclipselink-specific code.

Thanks
Gary