openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From holod <>
Subject Can't persist detached object
Date Tue, 09 Dec 2008 11:35:42 GMT

I'm in strange situation.
I have an entity Person.
I have an EJB stateless bean which has three methods:
1. public createPerson(Person newPerson){...}
2. public updatePerson(Person newPerson, Person oldPerson){...}
3. private attachFields(Person detachedPerson){...}

When I'm creating Person, my logic goes this way:
1. Outside bean Person is constructed, but It can have detached entities.
2. Invoke stateless bean -> createPerson(newPerson);
3. Inside this method attachFields(newPerson) in invoked.

Everything goes fine! All detached fields (for example only id of some
referenced entity is specified) are attached, Person is successfully

When I'm trying to update person, I get strange Exception (it's not strange,
but I can't get why does in happen).
1. Invoke updatePerson(newPerson, oldPerson); oldPerson is attached entity,
newPerson is a raw entity with detached referenced enitities.
2. delete referenced entities from oldPerson.
3. use em.flush(); to force deletion data from db.
4. set new fields from newPerson to oldPerson.
5  attachFields(oldPerson) now, oldPerson CAN'T have detached entities
6. use em.merge(oldPerson) to save newly created referenced entities

And... I get exception: can't persist detached entity! and JPA prints entity
class bla.bla2.SomeEntityClass + [it's key].
But It can't be so! I get this entity from EntityManager and save it to
field of oldPerson.
The same procedure works fine when I create Person.

I don't understand what's going on.

Is there any possibility to know more details about such exception? I've put
logger.debug everywhere and I clearly see how every field of person is taked
from EntityManager.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message