Announcement Announcement Module
Collapse
No announcement yet.
Spring+CMT+JDO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring+CMT+JDO

    Hello!

    Since I finally managed to get Spring transactions to work, I now want to try and use CMT instead of Spring transactions. From what I understand, I have to use the JtaTransactionManager instead of the JdoTransactionManager to achieve this. But, I guess it is not sufficient to just replace the JdoTransactionManager with the JtaTranactionManager (because it did not work) and unfortunately, I couldn't find a good example on how to do this.

    So, it would be nice if someone could point me to a basic example or could tell me what I have to change in my Spring managed transaction config file.

    I use the following setup:
    (1) A stateless session bean acts as a proxy for the service which is provided by Spring.
    (2) I use a command-line client and Spring to locate the EJB.
    (3) The transaction-type of the EJB is set to "Container"

    The configuration file for Spring managed transactions which is used in the EJB and which I want to "convert" to use CMT looks like this:

    Code:
    <bean id="pmf" class="com.signsoft.ibo.client.PersistenceManagerFactoryImpl" destroy-method="close">
        <property name="connectionDriverName" value="com.mysql.jdbc.Driver"/>
        <property name="connectionURL" value="jdbc:mysql://localhost:3306/cardb"/>
        <property name="connectionInfoName" value="com.signsoft.ibo.dbsupport.mysql.MySqlDatabaseInfo"/>
        <property name="connectionUserName" value="root"/>
        <property name="optimistic" value="true"/>
        <property name="logging" value="true"/>
        <property name="nontransactionalRead" value="false"/>
      </bean>
    
      <bean id="pmfProxy" class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
    	<property name="targetPersistenceManagerFactory" ref="pmf"/>
    	<property name="allowCreate" value="false"/>
      </bean>
    
      <bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
      	<property name="persistenceManagerFactory" ref="pmf"/>
      </bean>
    
      <tx:advice id="txAdvice" transaction-manager="transactionManager">
      	<tx:attributes>
    		<tx:method name="*" propagation="REQUIRED"/>
    	</tx:attributes>
      </tx:advice>
    
      <aop:config>
      	<aop:pointcut id="serviceMethods" expression="execution(* de.znt.service.MyService.*(..))"/>
    	<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
      </aop:config>
    
      <bean id="myService" class="de.znt.service.MyServiceImpl">
    	<constructor-arg ref="pmfProxy"/>
      </bean>

  • #2
    Ok, I have changed the applicationContext.xml file to what I believe should be the correct setup for CMT managed transactions. Unfortunately, I still get an "Write outside a transaction ..." exception.

    I would appreciate any comments on this setup or comments on what is missing. As I pointed out in my initial post, I could not find an example on how to do this, so every comment is helpful.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           					   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           					   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    
    <!-- This is the configuration for container managed transactions -->
    
      <bean id="pmf" class="com.signsoft.ibo.client.PersistenceManagerFactoryImpl" destroy-method="close">
        <property name="connectionDriverName" value="com.mysql.jdbc.Driver"/>
        <property name="connectionURL" value="jdbc:mysql://localhost:3306/cardb"/>
        <property name="connectionInfoName" value="com.signsoft.ibo.dbsupport.mysql.MySqlDatabaseInfo"/>
        <property name="connectionUserName" value="root"/>
        <property name="optimistic" value="true"/>
        <property name="logging" value="true"/>
        <property name="nontransactionalRead" value="false"/>
      </bean>
    
    	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    
    	<bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager" ref="transactionManager"/>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="myServiceTarget" class="de.znt.service.MyServiceImpl">
    		<constructor-arg ref="pmf"/>
      	</bean>
    
      	<bean id="myService" parent="txProxyTemplate">
    		<property name="target" ref="myServiceTarget"/>
    	</bean>
    
    </beans>
    The Exception:
    Code:
    Exception in thread "main" org.springframework.remoting.RemoteAccessException: Cannot access remote service [MyEJB]; nested exception is java.rmi.ServerException: RuntimeException; nested exception is: 
    	com.signsoft.ibo.core.services.impl.server.es.IBOJDOUserException: [IBO#2006] [RMI TCP Connection(58)-127.0.0.1] Write outside a transaction with nontransactional-write = false
    NestedThrowables:
    null
    Caused by: java.rmi.ServerException: RuntimeException; nested exception is: 
    	com.signsoft.ibo.core.services.impl.server.es.IBOJDOUserException: [IBO#2006] [RMI TCP Connection(58)-127.0.0.1] Write outside a transaction with nontransactional-write = false
    NestedThrowables:
    null
    	at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:386)
    	at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:196)
    	at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
    	at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
    	at org.jboss.ejb.Container.invoke(Container.java:873)
    	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.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
    	at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
    	at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
    	at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
    	at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
    	at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
    	at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
    	at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
    	at sun.rmi.transport.Transport$1.run(Transport.java:153)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: com.signsoft.ibo.core.services.impl.server.es.IBOJDOUserException: [IBO#2006] [RMI TCP Connection(58)-127.0.0.1] Write outside a transaction with nontransactional-write = false
    NestedThrowables:
    null
    	at com.signsoft.ibo.core.services.impl.server.es.ExceptionServiceImpl.createJDOException(Unknown Source)
    	at com.signsoft.ibo.core.services.impl.generics.os.GenericObjectStateServiceImpl.b(Unknown Source)
    	at com.signsoft.ibo.core.services.impl.generics.os.GenericObjectStateServiceImpl.a(Unknown Source)
    	at com.signsoft.ibo.core.services.impl.generics.os.GenericObjectStateServiceImpl.__makePersistentFirstPass(Unknown Source)
    	at com.signsoft.ibo.client.PersistenceManagerImpl.makePersistent(Unknown Source)
    	at de.znt.service.MyServiceImpl.storeCar(MyServiceImpl.java:70)
    	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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy118.storeCar(Unknown Source)
    	at de.znt.ejbtest.MxBean.storeCar(MxBean.java:138)
    	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.jboss.invocation.Invocation.performCall(Invocation.java:345)
    	at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
    	at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
    	at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
    	at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
    	at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
    	at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
    	at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
    	at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
    	at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
    	at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
    	... 24 more

    Comment

    Working...
    X