openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <adam....@cyberspaceroad.org>
Subject persisting an entity and JPA behaviour with referenced entities
Date Mon, 07 Apr 2008 12:09:02 GMT
I've got an issue with the persist operation, when I use a detached entity as 
one of the entity's referenced entities.

OpenJPA throws the
org.apache.openjpa.persistence.EntityExistsException: Attempt to persist 
detached object 
"org.apache.openjpa.enhance.org$permacode$atomictest$domain$Genus$pcsubclass@1c527be".

The situation is this: my MVC layer has received a new entity which it must 
create. The parent entity for this is found in a cache, in a detached state.

What I'd like to know, is why is JPA forcing me to merge this detached entity 
before allowing me to persist the new child?

It means I can't use the cache, or I have to program the DAO to merge all 
referenced entities. This latter option seems like a job that JPA should be 
doing. JPA knows this parent is a detached entity, so why can't it merge the 
managed entity?

I can't see any text in the EJB spec that would mandate this behaviour, yet 
Hibernate does it too.

Regards
Adam

Mime
View raw message