Atomikos Forum |
|
Hi,
I wrote a small Spring-Hibernate application that uses Atomikos(version-3.7.0) as a distributed transaction manager. I have an unsolved issue with the auto generated id,just to make it clear, I'm able to get the hibernate session (associated to the current transaction) and select or insert new entities, the problem is when I'm using the @GeneratedValue. The following is an entity that I mapped to a table: import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "USERS") @Access(AccessType.FIELD) public class User { @Id @GeneratedValue(strategy=GenerationType.AUTO) public int id; @Column(name = "NAME") public String name; public User() { } } The DAO I use: @Repository public class UsersDAO { @Autowired private HibernateTemplate template; @Transactional public <T> T findById(Class<T> clazz,Integer id){ return (T) template.get(clazz, id); } @Transactional(propagation=Propagation.REQUIRED, readOnly=false) public void save(User user){ template.persist(user); } } And the Spring configuration XML: <?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:annotation-config /> <bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" init-method="init" destroy-method="shutdownForce"> <constructor-arg> <props> <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop> </props> </constructor-arg> </bean> <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" depends-on="userTransactionService"> <!-- When close is called, should we force transactions to terminate or not? --> <property name="forceShutdown" value="false" /> <!-- IMPORTANT: disable startup because the userTransactionService above does this --> <property name="startupTransactionService" value="false"/> </bean> <bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService"> <property name="transactionTimeout" value="300" /> </bean> <!--- Configure the Spring framework to use JTA transactions from Atomikos --> <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="userTransactionService"> <property name="transactionManager" ref="AtomikosTransactionManager" /> <property name="userTransaction" ref="AtomikosUserTransaction" /> </bean> <bean id="mydatasource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="XADBMS" /> <property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" /> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password">1234</prop> <prop key="URL">jdbc:mysql://localhost:3306/test_transactions1</prop> </props> </property> <property name="minPoolSize" value="1" /> <property name="maxPoolSize" value="50" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name="configLocation" value="classpath:hibernate.cfg.xml" /> <qualifier value="sessionFactory"/> <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> <property name="dataSource" ref="mydatasource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.show_sql" >true</prop> <prop key="hibernate.formate_sql">true</prop> <!-- TRANSACTION_READ_UNCOMMITTED 1, TRANSACTION_READ_COMMITTED 2, TRANSACTION_REPEATABLE_READ 4, TRANSACTION_SERIALIZABLE 8 --> <prop key="hibernate.connection.isolation">4</prop> <prop key="hibernate.max_fetch_depth">3</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop> <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop> <prop key="hibernate.connection.release_mode">after_transaction</prop> <prop key="hibernate.current_session_context_class">jta</prop> <prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.c3p0.preferredTestQuery">SELECT 1</prop> <prop key="hibernate.bytecode.provider">javassist</prop> </props> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="jtaTransactionManager" /> <bean id="appContextHolder" class="com.inneractive.testAtomikos.ApplicationContext" /> <context:component-scan base-package="com.inneractive.testAtomikos"/> </beans> The issue is, a java.lang.NullPointerException, the stack trace as follow: java.lang.NullPointerException at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:563) at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:291) at org.hibernate.id.insert.AbstractReturningDelegate.releaseStatement(AbstractReturningDelegate.java:82) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:60) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321) at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130) at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778) at org.springframework.orm.hibernate3.HibernateTemplate$21.doInHibernate(HibernateTemplate.java:796) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.persist(HibernateTemplate.java:793) at com.inneractive.testAtomikos.UsersDAO.save(UsersDAO.java:23) at com.inneractive.testAtomikos.UsersDAO$$FastClassByCGLIB$$f1776210.invoke(<generated>) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) at com.inneractive.testAtomikos.UsersDAO$$EnhancerByCGLIB$$822a0c8c.save(<generated>) at com.inneractive.testAtomikos.TestAtomikos.testHibernateConfigured(TestAtomikos.java:34) 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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:81) at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:177) at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158) 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.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:189) at org.testng.internal.Invoker.invokeMethod(Invoker.java:666) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.runWorkers(TestRunner.java:1172) at org.testng.TestRunner.privateRun(TestRunner.java:757) at org.testng.TestRunner.run(TestRunner.java:608) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1158) at org.testng.TestNG.runSuitesLocally(TestNG.java:1083) at org.testng.TestNG.run(TestNG.java:999) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:203) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174) Does any one know/familiar with this issue? Is it a Spring/Hibernate/Atomikos issue? |