persistence@glassfish.java.net

Re: Persisting via cascading

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 23 Nov 2009 10:54:00 -0400

This should work. Is the child's ID generated? What Generator Type is
used? Is the ID a primitive value or an Object wrapper?
--Gordon

Gary Jacobson wrote:
> 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
>