File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Entity in two persistence units" Watch "Entity in two persistence units" New topic
Author

Entity in two persistence units

Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115
Hi,

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 ?

Thanks
Kathir
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: http://aspose.com/file-tools
 
subject: Entity in two persistence units
 
Similar Threads
Persistence.xml
Composite foreign key causing "object is not an instance of declaring class"?
Could not synchronize
JTA Transaction Mangement
Customizing EntityManager injection for multi-tenancy