Pasquale Imbemba [http://community.jboss.org/people/pi4630] created the 
discussion

"Multiple EntityManagers with different persistence units"

To view the discussion, visit: http://community.jboss.org/message/623935#623935

--------------------------------------------------------------
I've defined two persistence units in my persistence.xml: each one with its own 
data source (one points to an Oracle database on which I do reads, the other 
points to the HsqlDB I use to write).
Entity beans are mapped (by annotations) correctly. In my SLSB I inject two 
distinct EntityManagers, that refer to the relative name of the persistence 
units.

In my business method, I do a db read using the EntityManager pointing to the 
OracleDB and then I call a private method, where I instantiate a new entity 
which corresponds to a table on my HsqlDB. I then pass this object to 
myHsqlDbEMan.persist() method at the end of the private method.
Soon after the methods are terminated (and the server is committing changes to 
the database), I get the following error:

ERROR  
http://community.jboss.org/message/623935#623935#623935/org.hibernate.util.JDBCExceptionReporter
 Multiple EntityManagers with different persistence units 
(WorkerThread#0[127.0.0.1:48655]) Could not enlist in transaction on entering 
meta-aware object!; - nested throwable: (javax.transaction.SystemException: 
java.lang.Throwable: Unabled to enlist resource, see the previous warnings. 
tx=TransactionImple < ac, BasicAction: 0:ffff7f000101:126a:4e5def22:c 
status: ActionStatus.ABORT_ONLY >); - nested throwable: 
(org.jboss.resource.JBossResourceException: Could not enlist in transaction on 
entering meta-aware object!; - nested throwable: 
(javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist 
resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: 
0:ffff7f000101:126a:4e5def22:c status: ActionStatus.ABORT_ONLY >))
2011-08-31 10:22:49,884 ERROR  
org.hibernate.event.def.AbstractFlushingEventListener 
org.hibernate.event.def.AbstractFlushingEventListener 
(WorkerThread#0[127.0.0.1:48655]) Could not synchronize database state with 
session: org.hibernate.exception.GenericJDBCException: Cannot open connection



How do I handle two different persistence contexts? I've tried to refactor my 
SB as Stateful and extend the persistence context of both persistence units, 
but that didn't work (returned same error). I also tried to refactor that 
writeToDb() to another SessionBean and use the HsqlDB context only there and 
invoke the method from my other bean, but that didn't work either.
I presumed that by using the different EntityManager, the AS would know about 
which context the method is in.


Thanks in advance,
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/623935#623935]

Start a new discussion in Beginner's Corner at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]

_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to