Can't make Seam managed transactions work
chawax Mar 19, 2009 4:08 PMHi,
I try to run POJOs / JavaBeans Seam components on OpenEJB 3.0. For what I understood, I need to use Seam managed persistence context and Seam managed transactions and I sould have the same beahaviour as EJB3 session beans.
I could make Seam managed persistence context work thanks to Stuart Douglas help : http://www.seamframework.org/Community/SeammanagedPersistenceContextOnOpenEJB
Now I try to configure Seam managed transactions but I can't make it work.
The persistence.xml file is like this :
<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="t4Seam"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/jdbc/t4Seam</jta-data-source> <mapping-file>META-INF/orm-utils.xml</mapping-file> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="false"/> </properties> </persistence-unit> </persistence>
In components.xml I added this :
<transaction:ejb-transaction />
And my Seam components are like this :
@Transactional(TransactionPropagationType.REQUIRED) public class FileAppenderDaoBase implements FileAppenderDao { @In protected javax.persistence.EntityManager emanager; ... }
My unit tests call Groovy scripts that call my Saem components. It used to work when my Seam components were EJB3 session beans. But now they are POJOs I have the following stack trace :
------------------------------------------------------------------------------- Test set: TestSuite ------------------------------------------------------------------------------- Tests run: 66, Failures: 1, Errors: 0, Skipped: 64, Time elapsed: 12.094 sec <<< FAILURE! loadTestDatas(t4.core.utils.test.EJB3Container) Time elapsed: 0.576 sec <<< FAILURE! java.lang.reflect.InvocationTargetException 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:597) at t4.core.utils.test.EJB3Container$2.testComponents(EJB3Container.java:39) at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:162) at t4.core.utils.test.EJB3Container.loadTestDatas(EJB3Container.java:34) Caused by: java.lang.UnsupportedOperationException: no transaction at org.jboss.seam.transaction.NoTransaction.begin(NoTransaction.java:36) at org.jboss.seam.util.Work.workInTransaction(Work.java:42) at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89) 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 t4.core.utils.trace.internal.FileAppenderDaoBase_$$_javassist_0.create(FileAppenderDaoBase_$$_javassist_0.java) 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:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756) at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:766) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:754) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170) at t4.core.utils.groovy.TraceTestData.run(TraceTestData.groovy:24) 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:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756) at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:778) at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0(ScriptBytecodeAdapter.java:198) at t4.core.utils.groovy.TestDataInitializer.run(TestDataInitializer.groovy:10) ... 36 more
Anyone has an idea what happens ?
I have one more question about using both Seam components as EJB3 session beans or POJOs. I mean that a Seam EJB3 session bean could call a Seam POJO. Do these both components share persistence context (if I inject Seam managed persistence context of course) and transactions ?
Thanks in advance,
Olivier