lock occured in ejb transaction when commit to 2 different databases simultaneously.
as result: both database (data1 and data 2 are locked)
but separately or not in transaction is ok.
jboss 4.2.2, Hibernarte 3.2.5.ga
Code:
...
@Stateless
@Local(value = ProcessingLocal.class)
public class ProcessingBean implements ProcessingLocal
{
@EJB(beanName = "Data1Bean", beanInterface = Data1Local.class)
private Data1Local data1;
@EJB(beanName = "Data2Bean", beanInterface = Data2Local.class)
private Data2Local data2;
public void test() throws Exception
{
Entity1 e1 = new Entity1();
data1.merge(e1);
Entity2 e2 = new Entity2();
data2.merge(e2);
}
}
data-ds.xml
Code:
<datasources>
<xa-datasource>
<jndi-name>data1</jndi-name>
<xa-datasource-class>com.informix.jdbcx.IfxXADataSource</xa-datasource-class>
<xa-datasource-property name="IfxIFXHOST">serv1</xa-datasource-property>
<xa-datasource-property name="IfxIFX_LOCK_MODE_WAIT">100</xa-datasource-property>
<xa-datasource-property name="PortNumber">6666</xa-datasource-property>
<xa-datasource-property name="DatabaseName">data1</xa-datasource-property>
<xa-datasource-property name="ServerName">main</xa-datasource-property>
<xa-datasource-property name="User">informix</xa-datasource-property>
<xa-datasource-property name="Password">informix</xa-datasource-property>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<min-pool-size>5</min-pool-size>
<max-pool-size>1000</max-pool-size>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.InformixExceptionSorter
</exception-sorter-class-name>
<metadata>
<type-mapping>InformixDB</type-mapping>
</metadata>
</xa-datasource>
<xa-datasource>
<jndi-name>data2</jndi-name>
<xa-datasource-class>com.informix.jdbcx.IfxXADataSource</xa-datasource-class>
<xa-datasource-property name="IfxIFXHOST">serv1</xa-datasource-property>
<xa-datasource-property name="IfxIFX_LOCK_MODE_WAIT">100</xa-datasource-property>
<xa-datasource-property name="PortNumber">6666</xa-datasource-property>
<xa-datasource-property name="DatabaseName">data2</xa-datasource-property>
<xa-datasource-property name="ServerName">main</xa-datasource-property>
<xa-datasource-property name="User">informix</xa-datasource-property>
<xa-datasource-property name="Password">informix</xa-datasource-property>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<min-pool-size>5</min-pool-size>
<max-pool-size>1000</max-pool-size>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.InformixExceptionSorter
</exception-sorter-class-name>
<metadata>
<type-mapping>InformixDB</type-mapping>
</metadata>
</xa-datasource>
</datasources>
in unit 1
persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<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="data1" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/data1</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>
</persistence-unit>
</persistence>
in unit 2
persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<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="data2" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/data2</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>
</persistence-unit>
</persistence>
[/code]