Hi Harald,

The Java SE scenario you describe below is also not guaranteed to work. In Java 
SE many JPA providers use the persistence unit name as a unique identifier for 
the persistence unit and cache the return value. It really is expected that you 
have exactly one EntityManagerFactory (and therefore database connection) per 
persistence unit.

I'm a little confused as to the use case for this business intelligence 
application. These new databases are being added dynamically at runtime, but 
use the same table structure? This sounds, to me, as though your application 
needs to cope with these dynamic changes. Perhaps if you stop your persistence 
bundle, re-bind the DataSource services to point at the correct database, then 
bring the persistence bundle back up?

Regards,

Tim

----------------------------------------
> From: [email protected]
> To: [email protected]
> Date: Mon, 27 Sep 2010 13:57:19 +0200
> Subject: AW: JPA Service: EntityManagerFactoryBuilder
>
> Hi Tim,
>
> it seems I misinterpreted the EntityManagerFactoryBuilder - thanks for 
> pointing this out.
>
> But I still don't see how to solve the situation with one persistence unit 
> working on multiple databases with the same structure, neither in OSGi nor in 
> Java EE.
>
> In Java SE, I would simply call 
> Persistence.createEntityManagerFactory(puName, props) multiple times, with 
> the same persistence unit name, but different property sets, specifying 
> different datasources.
>
> E.g. think of a business intelligence application doing analysis on customer 
> databases, where there is a separate database for each country. Each analysis 
> request refers to given country, and the application has to select the 
> appropriate database at run-time. New countries may be added at any time, so 
> it would not work to hard-code n persistence units and/or EMFs up front.
>
> Best regards,
> Harald
>
                                          

Reply via email to