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 and other Java EE Technologies and the fly likes EJB - Work with multiple persistence units Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB - Work with multiple persistence units" Watch "EJB - Work with multiple persistence units" New topic
Author

EJB - Work with multiple persistence units

Chris Palau
Greenhorn

Joined: Jan 21, 2009
Posts: 4
Hi guys,

I need to develop an EJB that will work with 4 databases. I am looking in google for the best solution to work with 4 persistence units but I don't have a clear idea about the best solution and the most efficient one.

I dont' know if I inject using @PersistenceUnit() and EntityManagerFactory (one for each of the persistence units) and then create entityManagers using an EntityManagerFactory to choose the EntityManager for the selected persistence unit.

¿If I use 4 @persistentunit injects, will I consume 4 connections to the database ?

Please help.

Thanks !

Chris
Sebastien Villanueva Thurmes
Greenhorn

Joined: Apr 27, 2009
Posts: 2
Hi,

i am looking for this kind of informations too

i found this interesting link, how to overwrite properties of a PU : Hibernate link see 2.2.2. Bootstrapping

In my case, it should be very nice; i use some schemas in the same DB mysql, the only thing to do should be to override the schema property...

i have not yet tested this trick... i don't know if that work ...
Sebastien Villanueva Thurmes
Greenhorn

Joined: Apr 27, 2009
Posts: 2
Today, i make some tests:

i work with Netbeans, GlassFish, Derby

persistence.xml


my entity bean:


my stateless bean:


and my app-client:


and the glassfish logs:



i made a sql request on my table on derby:
select COUNT(*) from DBUSER.T_CADDYFOXUSER

and i have 1 row !!!

select * and i have all i have inserted


That's work whith the two technics:
  • Persistence.createEntityManagerFactory
  • EntityManagerFactory INJECTION


  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: EJB - Work with multiple persistence units
     
    Similar Threads
    EntityManager
    Cleared OCPBCD
    Recommended way of getting entity manager from pojo class
    SOS!! Simple yes/no question about JPA...
    Confusion in accessing ENTITY bean