tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karan Malhi <karan.ma...@gmail.com>
Subject Re: Extended PersistenceContext and Transactions
Date Wed, 11 Feb 2009 23:58:00 GMT
Hi Thomas,
I could not reproduce the error. Could you share the code?

On Mon, Feb 9, 2009 at 6:50 AM, <Thomas.TH.Hamacher@partner.bmw.ch> wrote:

> Hi @all,
>
> so now I tracked down my problem with the Extended PersistenceContext. The
> reason for failure was the TransactionManagement.
> Anyhow I tried to work with different possibilities of Transactions, but
> did not find a solution yet. So maybe someone can
> point me to the right direction.
>
> My scenario is as follows and pretty easy. I have one EntityManagerProvider
> using the injected EntityManager as described in
> http://www.nabble.com/Re%3A-Obtaining-an-EntityManager-instance-outside-an-EJB-p21701466.html
> .
> The I have another SessionBean, which should also be injected with an
> Extended EntityManager.
>
> The EntityManager is injected perfectly into my EntityManagerProvider, but
> when trying to use the second sessionBean with the extended EntityManager I
> run into various problems. As I read from the documentations, the Extended
> PersistenceContext works as follows: Any changes made to the entities are
> queued to the EntityManager. As soon as a new Transaction is started, the
> EntityManager joins this Transaction and commits changed to database.
>
> So therefor my first idea was, not to use a Transaction, because this
> should be done by the container - in this case openEJB.
> When I do so, it results in the following exception, when trying to obtain
> the delegate of the EntityManager:
>
> java.lang.IllegalStateException: InternalError: an entity manager should
> already be registered for this entended persistence unit
>        at
> org.apache.openejb.persistence.JtaEntityManagerRegistry.getEntityManager(JtaEntityManagerRegistry.java:91)
>        at
> org.apache.openejb.persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java:61)
>        at
> org.apache.openejb.persistence.JtaEntityManager.getDelegate(JtaEntityManager.java:92)
>        at
> org.apache.openejb.persistence.JtaEntityManager.getDelegate(JtaEntityManager.java:41)
>        at
> com.sepus.testUtil.commons.service.BaseApplicationServerProvider.getPersistenceProvider(BaseApplicationServerProvider.java:106)
>        at
> company.commons.service.impl.PopulatorServiceImpl.<init>(PopulatorServiceImpl.java:47)
>        at
> company.commons.environment.TestEnvironment.start(TestEnvironment.java:130)
>        at
> company.commons.environment.TestBase.startEnvironment(TestBase.java:29)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at
> org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
>        at
> org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
>        at
> org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
>        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
>        at
> org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:167)
>        at
> org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
>        at org.testng.TestRunner.runWorkers(TestRunner.java:712)
>        at org.testng.TestRunner.privateRun(TestRunner.java:582)
>        at org.testng.TestRunner.run(TestRunner.java:477)
>        at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
>        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
>        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
>        at org.testng.SuiteRunner.run(SuiteRunner.java:198)
>        at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:821)
>        at org.testng.TestNG.runSuitesLocally(TestNG.java:788)
>        at org.testng.TestNG.run(TestNG.java:708)
>        at
> org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:74)
>        at
> org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>
>
> (By the way: there is probably a typo in the Exception-message)
>
>
> Second try was to use the javax.persistence.EntityTransaction of the
> EntityManager. But as soon as I try to obtain the EntityTransaction I get
> the following Exception:
>
> java.lang.IllegalStateException: A JTA Entity Manager can not use an entity
> transaction
>        at
> org.apache.openejb.persistence.JtaEntityManager.getTransaction(JtaEntityManager.java:220)
>        at
> com.sepus.testUtil.commons.environment.TestEnvironment.start(TestEnvironment.java:127)
>        at
> com.sepus.testUtil.commons.environment.TestBase.startEnvironment(TestBase.java:29)
>        at
> org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:74)
>        at
> org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>
>
> Third solution was to use the javax.Transaction.TransactionManager. Not
> even better:
>
> DEBUG - finished invoking method create with
> exception:javax.ejb.EJBException: nested exception is:
> org.apache.openejb.persistence.EntityManagerAlread
> yRegisteredException: Another entity manager is already registered for this
> persistence unit
> javax.ejb.EJBException: nested exception is:
> org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException:
> Another entity manager is already
>  registered for this persistence unit
> org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException:
> Another entity manager is already registered for this persistence unit
>        at
> org.apache.openejb.persistence.JtaEntityManagerRegistry$ExtendedRegistry.addEntityManagers(JtaEntityManagerRegistry.java:191)
>        at
> org.apache.openejb.persistence.JtaEntityManagerRegistry$ExtendedRegistry.access$100(JtaEntityManagerRegistry.java:169)
>        at
> org.apache.openejb.persistence.JtaEntityManagerRegistry.addEntityManagers(JtaEntityManagerRegistry.java:129)
>        at
> org.apache.openejb.core.stateful.StatefulContainer.createEJBObject(StatefulContainer.java:288)
>        at
> org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:263)
>        at
> org.apache.openejb.core.ivm.EjbHomeProxyHandler.create(EjbHomeProxyHandler.java:270)
>        at
> org.apache.openejb.core.ivm.EjbHomeProxyHandler._invoke(EjbHomeProxyHandler.java:161)
>        at
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:286)
>        at $Proxy77.create(Unknown Source)
>        at
> org.apache.openejb.core.ivm.naming.BusinessLocalReference.getObject(BusinessLocalReference.java:33)
>        at
> org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:150)
>        at
> org.apache.openejb.core.ivm.naming.ContextWrapper.lookup(ContextWrapper.java:115)
>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>        at
> company.testUtil.commons.service.BaseApplicationServerProvider.lookup(BaseApplicationServerProvider.java:162)
>        at
> company.testUtil.commons.service.BaseApplicationServerProvider.getService(BaseApplicationServerProvider.java:145)
>        at
> company.testUtil.commons.service.BaseApplicationServerProvider.getService(BaseApplicationServerProvider.java:136)
>        at
> company.testUtil.commons.environment.TestEnvironment.getService(TestEnvironment.java:332)
>        at
> company..iis.test.core.populator.IISPopulator.getSvc(IISPopulator.java:39)
>        at
> company..iis.test.core.populator.RegionPopulator.populate(RegionPopulator.java:27)
>        at
> company.testUtil.commons.service.impl.PopulatorServiceImpl.doPopulate(PopulatorServiceImpl.java:176)
>        at
> company.testUtil.commons.service.impl.PopulatorServiceImpl.recursivePopulation(PopulatorServiceImpl.java:121)
>        at
> company.testUtil.commons.service.impl.PopulatorServiceImpl.populate(PopulatorServiceImpl.java:91)
>        at
> company.testUtil.commons.environment.TestEnvironment.start(TestEnvironment.java:133)
>        at
> company.testUtil.commons.environment.TestBase.startEnvironment(TestBase.java:29)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at
> org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
>        at
> org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
>        at
> org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
>        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
>        at
> org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:167)
>        at
> org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
>        at org.testng.TestRunner.runWorkers(TestRunner.java:712)
>        at org.testng.TestRunner.privateRun(TestRunner.java:582)
>        at org.testng.TestRunner.run(TestRunner.java:477)
>        at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
>        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
>        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
>        at org.testng.SuiteRunner.run(SuiteRunner.java:198)
>        at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:821)
>        at org.testng.TestNG.runSuitesLocally(TestNG.java:788)
>        at org.testng.TestNG.run(TestNG.java:708)
>        at
> org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:74)
>        at
> org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
>
>
> And lastly, using the UserTransaction did not succeed, as no
> UserTransaction has been injected and therefor has a null-value.
>
> So now I am a bit confused, how to work with the Extended
> PersistenceContext using openEJB and Hibernate as EntityManager.
>
> Can anybody maybe tell me, what I am missing or what I have to do to make
> it work?
>
> Thanks
> Thomas
>



-- 
Karan Singh Malhi

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message