users@glassfish.java.net

Re: Cannot get id of managed object instance in session bean method

From: <glassfish_at_javadesktop.org>
Date: Thu, 19 Jul 2007 14:38:40 PDT

> First I would like to point out that you do not need
> both the merge() and the persist() only the merge()
> is needed.

Yes I know the code looks not very elegant, but this came out when I stripped down the more complicated original method.

> To work around this issue there are a couple of
> things you can do. First, if you were to call
> flush() after the merge() call then the Child should
> have an ID when checked by the System.out code.
> Second, if you were to reverse the order of you
> merge(), persist() calls then the Child would have
> an ID assigned by the persist() call and the merge()
> call would simply have the managed Parent assigned
> to the managed Child

Yes, both approaches fix the problem, thanks.

> Please file an Issue Tracker issue.

Does this mean that my original code should also work?

Regards
Stephan
[Message sent by forum member 'smuehlst' (smuehlst)]

http://forums.java.net/jive/thread.jspa?messageID=227355