Multiple Datasources - When starting JBoss the entities are created in all datasources
tmarques Jan 19, 2012 12:43 PMHi guys,
I am facing a problem, and i "google it" for some time and i not found any solution.
Due to logistic issues i have to distribute the tables in different data bases. When i run the application Server, Jboss tries to create all entities in the different databases.
Software:
Jboss 5.1.0
JBoss ESB 4.9
Please view the details:
postgres-ds.xml:
<datasources>
<local-tx-datasource>
<jndi-name>FirstDS</jndi-name>
<connection-url>jdbc:postgresql://localhost:5432/application
</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<security-domain>database-access</security-domain>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<metadata>
<type-mapping>PostgreSQL</type-mapping>
</metadata>
</local-tx-datasource>
<local-tx-datasource>
<jndi-name>SecondDS</jndi-name>
<connection-url>jdbc:postgresql://localhost:5432/general
</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<security-domain>database</security-domain>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<metadata>
<type-mapping>PostgreSQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
persistence.xml
<persistence 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"
version="1.0">
<persistence-unit name="first" transaction-type="JTA">
<jta-data-source>java:/FirstDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="second"
transaction-type="JTA">
<jta-data-source>java:/SecondDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Entities:
@Entity
@Table(name = "table1")
@PersistenceContext(unitName = "first")
public class Table1 implements Serializable {...}
@Entity
@Table(name = "table2")
@PersistenceContext(unitName = "second")
public class Table2 implements Serializable {...}
For this case i expect that :
- table first only exist in FirstDS and
- table second only exists in SecondDS.
But when i consult log i see that JBoss is trying to create in the diferent data sources the two tables.
Any one can help?
Thanks
TM