Java Persistence API: Multiple Persistence Units problem
Hi,
I'm working with Java EE 5 and using the Java Persistence API 1.0. I have two databases, one db2 and one mysql. The connection to them are set properly and I have one table in each of these databases. I also have one Entity class for each table. The issue is that I'm getting troubles to connect both dbs in one operation. Here's my persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<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="MySQL-ejbPU" transaction-type="JTA">
<jta-data-source>jdbc/mySqlDB</jta-data-source>
<class>ejb.model.MySQLTable</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties/>
</persistence-unit>
<persistence-unit name="DB2-ejbPU" transaction-type="JTA">
<jta-data-source>jdbc/MyDB2DB</jta-data-source>
<class>ejb.model.MyDB2Table</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
And here's my session facade:
@Stateless
publicclass TablesFacadeimplements TablesFacadeRemote{
@PersistenceContext(unitName="MySQL-ejbPU")
private EntityManager emMySql;
@PersistenceContext(unitName="DB2-ejbPU")
private EntityManager emDb2;
(...)
publicvoid create(MyDB2Table db2, MySQLTable mySql){
emMySql.persist(mySql);
emDb2.persist(db2);
}
(...)
}
I'm getting the following exception:
RAR5027:Unexpected exception in resource pooling
java.lang.IllegalStateException: Local transaction already has 1 non-XA Resource: cannot add more resources.
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.enlistResource(J2EETransactionManagerOpt.java:111)
at com.sun.enterprise.resource.SystemResourceManagerImpl.enlistResource(SystemResourceManagerImpl.java:87)
(...)
I'm wondering if this problem is related to the fact I want both to be container managed... Any ideas on how to resolve this?
Thanks in advance
Aurelio

