I hadn't set the child entity as not nullable. My English is pretty poor but I'll see if I can explain the issue more clearly.
I have a list of cities that are stored in an excel file, I pull them in and for each one I create a City entity. The addresses get pulled in to my system using Tibco and pre-persist I lookup the city field in the Tibco data and try to match it against one of my City entities to create the master/child relationship (Address-->City). Generally this all works fine but people do mistype the name of the city in the ERP so when the address data comes in via Tibco I can't always match the city the user typed to any of my City entities, so the admin gets an alert that the address needs to be fixed manually. The admin goes in and locates the Address entity in question and selects the appropriate City entity and saves the Address. My issue was that because of my JSF and bean code, it was possible to end up with a nulled City in the Address. Whenever this happens and I call merge I will get the exact error you reported. The error never made any sense to me because I can't understand how the entity could be detached, because there was no entity (for the City). Subsequently, because of my fumbling fingers I have created similar situations during coding and in all cases that I saw this very same error. Now I can't say that this is your error, but I can say that you will get this error if you do what I did. Chris -----Original Message----- From: Daryl Stultz [mailto:da...@6degrees.com] Sent: Thursday, 20 August 2009 7:43 AM To: users@openjpa.apache.org Subject: Re: Encountered unmanaged object On Wed, Aug 19, 2009 at 6:18 PM, C N Davies <c...@cndavies.com> wrote: > > I have had this issue quite a number of times, it turned out to be a logic > issue in the base class for my in my backing bean that would null out the > child entity in an main entity, when this condition occurs I will always > get > this error. I don't mean to beat this to death, but if the child entity of the main entity was nulled and the property was declared not nullable, then you should have gotten a error regarding the null, not "unmanaged entity", right? And if it was nullable, it should have happily persisted the main entity. Sorry, still confused, and trying to understand the inner workings better. It seems to me the child entity is not really null, but it's (enhanced) state got messed up. -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com mailto:da...@6degrees.com