-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: java.lang.NullPointerException at rollback
PostPosted: Wed Feb 11, 2004 11:25 am 
Beginner
Beginner

Joined: Tue Nov 18, 2003 10:16 am
Posts: 33
Location: Cluj-Napoca, Romania
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]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 11:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please show your calling code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You must not use an Hibernate session after it raised an exception

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 4:12 am 
Beginner
Beginner

Joined: Tue Nov 18, 2003 10:16 am
Posts: 33
Location: Cluj-Napoca, Romania
I never use Hibernate Sesion, I am using HibernateTemplate instead.


Code looks like this:

DAO object:

public class UserDAO extends HibernateDaoSupport
{
..
public void saveUser(User user)
{
getHibernateTemplate().save(user);
}
...
}


The Service class looks mainly like this:

public class UserServiceImpl implements UserService
{
private UserDAO userDAO;
public UserDAO getUserDAO()
{
return userDAO;
}

public void setUserDAO(UserDAO userDAO)
{
this.userDAO = userDAO;
}
.......
//the business method
public void save2Users()
{
user = new User("name", "login_name", "pass" );
userDAO.saveUser(user);

user2 = new User("other name", "login_name", "pass2");
//this throws exception!!!!
userDAO.saveUser(user2);
}//
}//UserServiceImpl


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.