This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EJB - Work with multiple persistence units

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


  •  
    You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
      Bookmark Topic Watch Topic
    • New Topic