File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Entity in two persistence units Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Entity in two persistence units" Watch "Entity in two persistence units" New topic

Entity in two persistence units

Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115

I have two persistence units in one persistence.xml
Each persistence unit connected with separate database and using Hibernate.
say Entitymanager em1 for persistence unit1 and
Entitymanager em2 for persistence unit2.
I get an entity from em1 using JPQL and it has values.
I want to persist this entity with em2.
I am getting an error "detached entity passed to persist."

Can some one post how do achieve this ?

Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Did you try to merge the object with em2

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115
Yes, the merge is working fine.

thank you
I agree. Here's the link:
subject: Entity in two persistence units
jQuery in Action, 3rd edition