This content has been marked as final.
Show 6 replies
-
1. Re: Multiple datasources?
c_eric_ray Apr 4, 2007 12:11 PM (in response to marcosh)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 -
2. Re: Multiple datasources?
marcosh Apr 4, 2007 5:07 PM (in response to marcosh)Ok!!!!!!
Thanks for the reply, it works fine!! -
3. Re: Multiple datasources?
baz Apr 12, 2007 11:58 AM (in response to marcosh)I have followed the advise, but still having the problem in the first post.
My entities are bound to both datasources.
I do not have a clue what i have missed:-(
[qoute]bind my entities using the @PersistenceUnits annotation -
4. Re: Multiple datasources?
baz Apr 12, 2007 11:59 AM (in response to marcosh)Sorry, tried again.
I have followed the advise, but still having the problem in the first post.
My entities are bound to both datasources.
I do not have a clue what i have missed:-(bind my entities using the @PersistenceUnits annotation
Perhaps this is the key. But in which way i must anotate my entities?
Ciao,
Carsten -
5. Re: Multiple datasources?
baz Apr 13, 2007 2:14 AM (in response to marcosh)marcosH
would you be so kind to share your solution with me? -
6. Re: Multiple datasources?
baz Apr 13, 2007 2:15 AM (in response to marcosh)marcosH
would you be so kind to share your solution with me?