[jboss-user] [JBoss Seam] - Re: Multiple datasources?
c_eric_ray
do-not-reply at jboss.com
Wed Apr 4 12:11:48 EDT 2007
datasource...
| <datasources>
|
| <local-tx-datasource>
| <jndi-name>PostgresDS1</jndi-name>
| <connection-url>jdbc:postgresql://localhost:5432/db1</connection-url>
| <driver-class>org.postgresql.Driver</driver-class>
| <user-name>db1</user-name>
| <password>db1</password>
| <max-pool-size>35</max-pool-size>
| <blocking-timeout-millis>60000</blocking-timeout-millis>
| <metadata>
| <type-mapping>PostgreSQL 8.0</type-mapping>
| </metadata>
| </local-tx-datasource>
|
| <local-tx-datasource>
| <jndi-name>PostgresDS2</jndi-name>
| <connection-url>jdbc:postgresql://localhost:5432/db2</connection-url>
| <driver-class>org.postgresql.Driver</driver-class>
| <user-name>db2</user-name>
| <password>db2</password>
| <max-pool-size>35</max-pool-size>
| <blocking-timeout-millis>60000</blocking-timeout-millis>
| <metadata>
| <type-mapping>PostgreSQL 8.0</type-mapping>
| </metadata>
| </local-tx-datasource>
|
| </datasources>
|
persistence.xml...
| <persistence version="1.0"
| xmlns="http://java.sun.com/xml/ns/persistence"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
| http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
|
| <persistence-unit name="db1-PU" transaction-type="JTA">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/PostgresDS1</jta-data-source>
| <properties>
| <property name="show_sql" value="true"/>
| <property name="hibernate.hbm2ddl.auto" value="update"/>
| <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
| <property name="jboss.entity.manager.jndi.name" value="java:/DB1EntityManager"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/DB1EntityManagerFactory"/>
| </properties>
| </persistence-unit>
|
| <persistence-unit name="db2-PU" transaction-type="JTA">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/PostgresDS2</jta-data-source>
| <properties>
| <property name="show_sql" value="true"/>
| <property name="hibernate.hbm2ddl.auto" value="update"/>
| <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
| <property name="jboss.entity.manager.jndi.name" value="java:/DB2EntityManager"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/DB2EntityManagerFactory"/>
| </properties>
| </persistence-unit>
| </persistence>
|
Source code...
| @PersistenceContext(unitName="db1-PU")
| private EntityManager db1EntityManager;
|
| @PersistenceContext(unitName="db2-PU")
| private EntityManager db2EntityManager;
|
Notice the <jta-data-source> value in the persistence.xml matches the <jndi-name> in the datasource. Then the source code annotates two different instances of an EntityManager with the appropriate PersistenceContext
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034669#4034669
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034669
More information about the jboss-user
mailing list