-->
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.  [ 2 posts ] 
Author Message
 Post subject: Error when begin transaction
PostPosted: Fri Jun 13, 2008 9:16 pm 
Newbie

Joined: Fri Jun 13, 2008 11:27 am
Posts: 6
I save object with the following code:

public boolean saveAndUpdate(TblCustomerInfo customerInfo) {

Session session=getHibernateTemplate().getSessionFactory().openSession();
try{
Transaction tx=session.beginTransaction();
session.saveOrUpdate(customerInfo);
tx.commit();

if(tx!=null){
try{
tx.rollback();
}
catch(HibernateException ex){
ex.printStackTrace();
}
}
}
catch(HibernateException ex){
ex.printStackTrace();
}

return true;
}


But it give the error:

org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
at com.callcenter.dao.impl.CustomerManagerDAOImpl.saveAndUpdate(CustomerManagerDAOImpl.java:73)
at com.callcenter.service.impl.CustomerManagerImpl.saveAndUpdate(CustomerManagerImpl.java:38)
at com.callcenter.web.pages.EditCustomer.onSuccess(EditCustomer.java:26)
at com.callcenter.web.pages.EditCustomer.dispatchComponentEvent(EditCustomer.java)
at org.apache.tapestry.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:843)
............



and i query the table,the data is saved with this error,how to remove this error???


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 12:36 am 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
try{
tx.rollback();
}

put this code in exception block.. you need to rollback only when the exception accurs and not on succefull commit..

Regards,

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.