事务同步注册问题

时间:2011-07-19 19:42:58

标签: transactions jboss seam jta

对于我们使用Seam构建的Web应用程序,有一堆服务器测试用例。它们运行在多个系统上(Mac OS X和Linux);通常,您可以克隆存储库并运行测试用例而没有任何问题。

但是,测试用例不能在我们团队中的一个人的笔记本电脑上运行。他在联想笔记本电脑上使用Fedora Core。当应用程序部署到Seam用于单元/集成测试的嵌入式JBoss时,我们遇到以下异常:

javax.persistence.PersistenceException:
org.hibernate.TransactionException: Could not register synchronization
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
   at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:547)
   at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:82)
   at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:61)
   at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)
   at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:34)
   at org.jboss.ejb3.entity.InjectedEntityManagerFactory.createEntityManager(InjectedEntityManagerFactory.java:78)
   at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:79)
   at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:108)
   at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
   at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
   at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
   at org.jboss.seam.Component.unwrap(Component.java:2301)
   at org.jboss.seam.Component.getInstance(Component.java:2044)
   at org.jboss.seam.Component.getInstance(Component.java:1986)
   at org.jboss.seam.Component.getInstance(Component.java:1980)
   at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2375)
   at org.jboss.seam.Component.getValueToInject(Component.java:2327)
   at org.jboss.seam.Component.injectAttributes(Component.java:1739)
   at org.jboss.seam.Component.inject(Component.java:1557)
   at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
   at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
   at org.jboss.seam.util.Work.workInTransaction(Work.java:61)
   at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
   at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
   at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
   at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
   at com.ambitz.everest.bootstrap.EverestBootstrap_$$_javassist_seam_9.initializeEverest(EverestBootstrap_$$_javassist_seam_9.java)
   at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
   at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
   at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
   at org.jboss.seam.core.Events.raiseEvent(Events.java:85)
   at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:145)
   at org.jboss.seam.init.Initialization.init(Initialization.java:747)
   at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:919)
   at com.ambitz.everest.test.JUnitSeamTest.startContainer(JUnitSeamTest.java:65)
   at com.ambitz.everest.test.EverestServerTestSuite.setUpBeforeClass(EverestServerTestSuite.java:47)
Caused by: org.hibernate.TransactionException: Could not register synchronization
   at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:213)
   at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:470)
Caused by: java.lang.IllegalStateException: [com.arjuna.ats.internal.jta.transaction.arjunacore.syncsnotallowed] [com.arjuna.ats.internal.jta.transaction.arjunacore.syncsnotallowed] Synchronizations are not allowed!
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.registerSynchronizationImple(TransactionImple.java:473)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.registerSynchronization(TransactionImple.java:441)
   at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:210)

测试环境使用HSQLDB 2.1.0。

正如我已经说过的,测试用例可以在其他Linux机器上运行(也可以使用Fedora Core)。有谁知道,可能会影响CMTTransaction什么,以便在这台特定的机器上不允许进行事务同步注册?

1 个答案:

答案 0 :(得分:2)

与此同时,我们发现了问题和解决方案:问题是arjuna无法解析机器的主机名,因此无法为事务创建UID。有趣的是,此信息仅以WARN严重性记录,但对事务同步有影响。

解决方案:我们将/etc/hosts的机器主机名添加到127.0.0.1