Hmmmmm.....
You could use a custom class-loader to load different persistance.xml's
You could generate the persistence.xml's on the fly, use a custom
ClassLoader to substituting your dynammically generated
persistence.xml and forget about injection of the em, and create the
em you require using an EntityManagerFactory reloaded from this custom
classloader
Maintain a pool of EMFs in a hashmap keyed by the customer.
Creating an EM from an EMF is fast. Initializing the EMF is what's slow.
Create the EM for the customer whenever you need one.
(Screaming ugly hack I know)
-Stephen
On Nov 21, 2007 10:10 AM, Alessandro Pedrotti <alessandrop_at_anthesi.it> wrote:
> This is exacly the scenario i want to avoid, because the various PU,
> must be statically defined in the persistence.xml.
>
> To implement a solution of this type i must preprocess my .ear file for
> each deployment target, changing the persistence.xml that must
> statically contain alle the existant jdbc connection pools (datasources).
>
> Adding afterward a connection pool (for me it happens when configuring a
> new customer, that owns its separated database) means a preprocess of
> the ear, seeeking for all the target connection pools, a change of the
> persistence.xml and a redeploy of the application.
>
> The two j2ee roles, the ear packager and the asadmin must be in sync
> with this, because the .ear become target dependent, and it's not a
> default.
>
> With this scenario the introduction of jpa will delay, because those
> actions must be performed by a maintenance script, that must be
> created, tested, committed and deployed on all our customer platforms.
> A little logical overhead implies a huge maintenance overhead
>
> Is there the way to put the persistence.xml in the appl server config
> (like domain.xml) and not in the ear? this will be the fantastic final
> solution to all these troubles.....
>
>
>
>
>
> Marina Vatkina wrote:
> > The only idea that I had so far was to define several PUs (that are
> > exactly the same with the exception of the datasource ref), and lookup
> > the EM (or EMF depending on your setup) that corresponds to the
> > datasource of your choice.
> >
> > Regards,
> > -marina
> >
> > Alessandro Pedrotti wrote:
> >> Any suggestion to this scenario
> >>
> >> DEVELOPMENT PLATFORM:
> >>
> >> 1 development database
> >>
> >> PRODUCTION ENVIRORMENT 1
> >>
> >> customer database 1
> >> customer database 2
> >> customer database 3
> >>
> >> PRODUCTION ENVIRORMENT 2
> >>
> >> customer database 4
> >> customer database 5
> >>
> >>
> >> how can i use persistencein ejbs in such envirorment? the persistence
> >> api cannot let me dynamically inject EntityManager.
> >> In a normal j2ee application i connect to database dynamically making
> >> a jndi lookup of the jdbc connection through normal jndi lookup,
> >> staring from the database jndi name.
> >>
> >> While the connection pool can be deployed outside the application
> >> (outside the .ear, it's only glassfish config), the persistence
> >> framework narrow me to have one ear that must fit the various
> >> persistence.xml units that points to each production database
> >>
> >> I've tried all the methods from documentation, but no workaround
> >> found for this trouble.
> >>
> >> Any suggestion?
> >>
> >> ANYONE THAT SHARE THE SAME PROBLEM? I THINK THIS IS A TROUBLE OF ALL
> >> J2EE IN-SERVICE APPLICATIONS....
> >>
> >>
> >> thanks in advance...
> >>
>
> --
> __________________
>
> Alessandro Pedrotti
>
>
> Anthesi s.r.l.
> via M.Misone, 14 - Riva del Garda (ITALY)
> Tel. +39 0464 553300 Fax. +39 0464 559010
>
> Http://www.anthesi.it - www.isiportal.com
>
>
> -----------------------------------------------------------------------
> Nota di riservatezza : Il presente messaggio, corredato dei relativi allegati, contiene informazioni da considerarsi strettamente riservate,ed è destinato esclusivamente al destinatario sopra indicato, il quale è l'unico autorizzato ad usarlo, copiarlo e, sotto la propria responsabilità, diffonderlo.Chiunque ricevesse questo messaggio per errore o comunque lo leggesse senza esserne legittimato è avvertito che trattenerlo, copiarlo, divulgarlo, distribuirlo a persone diverse dal destinatario è severamente proibito, ed è pregato di rinviarlo immediatamente al mittente distruggendone l'originale. Grazie.
> Confidentiality Notice : This message, together with its annexes, contains information to be deemed strictly confidential and is destined only to the addressee(s) identified above who only may use, copy and, under his/their responsibility, further disseminate it. If anyone received this message by mistake or reads it without entitlement is forewarned that keeping, copying, disseminating or distributing this message to persons other than the addressee(s) is strictly forbidden and is asked to transmit it immediately to the sender and to erase the original message received. Thank you.
>