| 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.createEntityManagerFactoryEntityManagerFactory INJECTION
|
 |
 |
|
|
subject: EJB - Work with multiple persistence units
|
|
|