Forums Register Login

EJB - Work with multiple persistence units

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ...
+Pie Number of slices to send: Send
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 guys haven't done this much, have ya? I suggest you study this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 3281 times.
    Similar Threads
    Non matching type for inject of field
    Difference in @PersistenceUnit and @PersistenseContext
    Grave: org/hibernate/proxy/EntityNotFoundDelegate
    spring wont inject the entitymanager
    EJB3 Beta Certification - EntityManager BASIC notes.
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 01:57:58.