persistence@glassfish.java.net

Re: multiple databases

From: Stephen Connolly <stephen.alan.connolly_at_gmail.com>
Date: Tue, 20 Nov 2007 22:37:29 +0000

I had some experience with that technique.

The only issue I had was remembering which PU the object came from (or
you end up merging it back to the wrong one! With great fun when the
@Id keys overlap!!!)

You nearly need to keep (Concurrent)HashSet of the objects, only
hashed based on Object.hashCode() and equality compared based on
Object.equals() as opposed to the hashCode() and equals() that depend
on the @Id fields (as is best practice for JPA) to track which objects
came from which PUs

-Stephen

On Nov 20, 2007 10:14 PM, Marina Vatkina <Marina.Vatkina_at_sun.com> 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...
> >
>