persistence@glassfish.java.net

Re: two connections with a persistence unity

From: Tom Ware <tom.ware_at_oracle.com>
Date: Fri, 04 Jul 2008 09:28:52 -0400

Hi Daniel,

   At the moment, TopLink Essentials does not support using connections that are
defined differently within the same EntityManagerFactory. Here is the Issue
Tracker issue that tracks this feature request:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=1575

   The workaround is to create multiple versions of your persistence unit and
use different login information for each.

-Tom

Daniel Benítez wrote:
> Hey everybody, We need help!!!
>
> For a connection with a Derby data base we are using a glassfish
> persistence unit. For that, we have created that persistence unit through
> Netbeans and with:
>
> protected EntityManager em;
> private static EntityManagerFactory emf;
>
> Properties databaseProperties = new Properties();
> databaseProperties.setProperty(oracle.toplink.essentials.config.TopLinkProperties.JDBC_URL, jdbcUrl);
> databaseProperties.setProperty(oracle.toplink.essentials.config.TopLinkProperties.JDBC_DRIVER, "org.apache.derby.jdbc.ClientDriver");
> databaseProperties.setProperty(oracle.toplink.essentials.config.TopLinkProperties.JDBC_USER, Usuario);
> databaseProperties.setProperty(oracle.toplink.essentials.config.TopLinkProperties.JDBC_PASSWORD, Contrasenya);
>
>
> emf = Persistence.createEntityManagerFactory(Manejador, databaseProperties);
> em = emf.createEntityManager( );
>
> as a code.
>
> The problem is that when we want to change the initial data base (using
> for that, destroy funtion (
>
> public void destruir(){
> em.clear();
> em.close();
> em = null;
>
> emf.close();
> //emf = null;
> }
>
> ) eliminating the class and establishing a new
> connection for this new data base ¡we always obtain a connection with the
> initial data base!!!
>
> What are we doing wrongly ?
>
> Is it possible to connect an unique persistence unit to different data
> base? How?
>
> Thanks very much for the help