I am using Spring for transaction management in my application, more precisely TransactionProxyFactoryBean proxy.
Calling service methods I succed to call dao methods within a single transaction, it commits and rollbacks correcly at database level, but at rollback, my dao object throws a NullPointerException.
Other strange thing: when an exception is thrown from a dao method and rollback must be called, the log INFO shows the message:
[code]INFO: Committing transaction on method [/code]
instead of a rolling back message. But the transaction is rollebacked.
here is complete trace of the output:
[code]Feb 11, 2004 5:09:17 PM org.springframework.transaction.interceptor.TransactionInterceptor invoke
INFO: Creating transaction for method 'addTestTransaction'
Feb 11, 2004 5:09:17 PM org.springframework.jdbc.datasource.DriverManagerDataSource getConnectionFromDriverManager
INFO: Creating new JDBC connection to [jdbc:mysql://localhost:3306/forum]
Hibernate: insert into user (name, login, password, type, email, info) values (?, ?, ?, ?, ?, ?)
Hibernate: SELECT LAST_INSERT_ID()
Hibernate: insert into category (name, info) values (?, ?)
Feb 11, 2004 5:09:17 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1062, SQLState: S1009
Feb 11, 2004 5:09:17 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Invalid argument value, message from server: "Duplicate entry 'asd' for key 2"
Feb 11, 2004 5:09:17 PM net.sf.hibernate.JDBCException <init>
SEVERE: Could not insert
java.sql.SQLException: Invalid argument value, message from server: "Duplicate entry 'asd' for key 2"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1750)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1596)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202)
at org.springframework.orm.hibernate.HibernateTemplate$2.doInHibernate(HibernateTemplate.java:220)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:144)
at org.springframework.orm.hibernate.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:218)
at ro.gebs.forum.dao.CategoryDAO.saveCategory(CategoryDAO.java:36)
at ro.gebs.forum.service.UserServiceImpl.addTestTransaction(UserServiceImpl.java:170)
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:324)
at org.springframework.aop.interceptor.AbstractReflectionInvokerInterceptor.invoke(AbstractReflectionInvokerInterceptor.java:54)
at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:152)
at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216)
at org.springframework.aop.framework.AopProxy.invoke(AopProxy.java:102)
at $Proxy0.addTestTransaction(Unknown Source)
at ro.gebs.forum.service.UserServiceImpl.main(UserServiceImpl.java:212)
java.sql.SQLException: Invalid argument value, message from server: "Duplicate entry 'asd' for key 2"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1750)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1596)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202)
at org.springframework.orm.hibernate.HibernateTemplate$2.doInHibernate(HibernateTemplate.java:220)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:144)
at org.springframework.orm.hibernate.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:218)
at ro.gebs.forum.dao.CategoryDAO.saveCategory(CategoryDAO.java:36)
at ro.gebs.forum.service.UserServiceImpl.addTestTransaction(UserServiceImpl.java:170)
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:324)
at org.springframework.aop.interceptor.AbstractReflectionInvokerInterceptor.invoke(AbstractReflectionInvokerInterceptor.java:54)
at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:152)
at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216)
at org.springframework.aop.framework.AopProxy.invoke(AopProxy.java:102)
at $Proxy0.addTestTransaction(Unknown Source)
at ro.gebs.forum.service.UserServiceImpl.main(UserServiceImpl.java:212)
Feb 11, 2004 5:09:17 PM org.springframework.transaction.interceptor.TransactionInterceptor invoke
INFO: Committing transaction on method 'addTestTransaction'
java.lang.NullPointerException
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2141)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2017)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2004)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:261)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:134)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:168)
at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216)
at org.springframework.aop.framework.AopProxy.invoke(AopProxy.java:102)
at $Proxy0.addTestTransaction(Unknown Source)
at ro.gebs.forum.service.UserServiceImpl.main(UserServiceImpl.java:212)[/code]
|