[jboss-user] [JBoss Seam] - Re: Change Database Connection at Runtime

knuwu do-not-reply at jboss.com
Fri Sep 28 04:20:32 EDT 2007


Hi breaveFencer

In your resources/WEB-INF/components.xml configuration file you find the following line:


  | <core:managed-persistence-context name="entityManager"
  |     auto-create="true"
  |     persistence-unit-jndi-name="java:/yourDBnameEntityManagerFactory" />          
  | 

Where "yourDBname" is normaly the name of your db reference in /META-INF/persistence.xml


  |    <persistence-unit name="yourDBname">
  |       <provider>org.hibernate.ejb.HibernatePersistence</provider>
  |       <jta-data-source>java:/yourDBnameDatasource</jta-data-source>
  |       <properties>
  |          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
  |          <property name="hibernate.cache.use_query_cache" value="true"/>
  |          <property name="hibernate.show_sql" value="true"/>
  |          <property name="jboss.entity.manager.factory.jndi.name" value="java:/yourDBnameEntityManagerFactory"/>
  |       </properties>
  |    </persistence-unit>
  | 

which is actually a reference to the jboss *-ds.xml configuration.

You may configure a second database connection (an addition *-ds.xml, a new enty in your persitence.xml and components.xml).


  | <core:managed-persistence-context name="entityManager2"
  |     auto-create="true"
  |     persistence-unit-jndi-name="java:/yourOtherDBnameEntityManagerFactory" />          
  | 

On code level you may reference the new entityManager with


  | entityManager= (EntityManager) Component.getInstance( "entityManager2" );
  | 

The old one with

  | entityManager= (EntityManager) Component.getInstance( "entityManager" );
  | 
  | Or simply with annotation
  | 
  | @In EntityManager entityManager;
  | 

Can not garantee this works but i would try it.

Greetings Ralph

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4089585#4089585

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4089585



More information about the jboss-user mailing list