-->
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.  [ 3 posts ] 
Author Message
 Post subject: Logical Unit of Work Rollback
PostPosted: Fri Apr 30, 2004 1:46 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
Hi,

I'm having problems rolling back my entire transaction. One of the update statements generates an SQLException which I trap and then rollback.

Rolling back doesn't roll back the entire transaction, however. Only the failed update.

Can someone help?

Here's what my code looks like:

Transaction t = null;
Session s = null;

try {
s = openSession(); // thread local session pattern
t = s.beginTransaction();

do updates... 1 ... N // update n fails

if (t != null) t.commit();
} catch (HibernateException) {
if (t != null) try { t.rollback } catch (...) {...}
throw new MyException(...);
}

All the successful updates 1...n-1 are still committed to the database.

Here's the stack trace:

Hope this comes out in a readable fashion and thanks for any help.

2004-04-30 10:25:05,843 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] ORA-20001: Status 5 Loans Must Be Rate Locked!
ORA-06512: at "PUB.PTP_LOANS_CLIENT_STATUS", line 28
ORA-04088: error during execution of trigger 'PUB.PTP_LOANS_CLIENT_STATUS'

2004-04-30 10:25:05,843 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] ORA-20001: Status 5 Loans Must Be Rate Locked!
ORA-06512: at "PUB.PTP_LOANS_CLIENT_STATUS", line 28
ORA-04088: error during execution of trigger 'PUB.PTP_LOANS_CLIENT_STATUS'

2004-04-30 10:25:05,859 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] Could not synchronize database state with session
java.sql.BatchUpdateException: ORA-20001: Status 5 Loans Must Be Rate Locked!
ORA-06512: at "PUB.PTP_LOANS_CLIENT_STATUS", line 28
ORA-04088: error during execution of trigger 'PUB.PTP_LOANS_CLIENT_STATUS'

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at weblogic.jdbc.pool.Statement.executeBatch(Statement.java:957)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:50)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:105)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2103)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2062)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
at com.ditech.loanexceptions.ejb.LoanExceptionsBean.approve(LoanExceptionsBean.java:183)
at com.ditech.loanexceptions.ejb.LoanExceptionsBean_79ohop_EOImpl.approve(LoanExceptionsBean_79ohop_EOImpl.java:475)
at com.ditech.loanexceptions.actions.ApproveLoanExceptionAction.doAction(ApproveLoanExceptionAction.java:78)
at com.ditech.loanexceptions.actions.AppBaseAction.execute(AppBaseAction.java:81)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:262)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:198)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2678)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2412)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:140)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:121)
2004-04-30 10:25:05,859 ERROR [com.ditech.loanexceptions.ejb.LoanExceptionsBean] approve: HibernateException - ROLLING BACK
2004-04-30 10:25:05,890 ERROR [com.ditech.loanexceptions.ejb.LoanExceptionsBean] approve: HibernateException occured


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 3:26 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Questions:
What does your openSession() method do? Does it return a possibly already existing session? Or does it return a brand new session, that ONLY this thread uses?

My thinking is, that you're "getting" a session that is possibly open already, and possibly in use by another thread. So when one of them (threads) commits, it updates all the saves/updates up till that point done by any other thread using the same session.

Perhaps have a centralised SessionFactory, but have each thread use the SessionFactory's openSession() to create its own session, self contained within the Thread, so that no other Thread can access it and do a commit.

-G


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 12:29 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
I changed my transaction factory from net.sf.hibernate.transaction.JTATransactionFactory to JDBCTransactionFactory and was able to get rollback to work properly.

I read in another post that the SessionFactory must somehow be bound to the container, but am not sure how to do this.

Can someone help with this?

I'm using a Configuration class instead of the XML properties file so when I create the SessionFactory my code looks as follows:

Configuration cfg = new Configuration();
// load several properties

SessionFactory sessionFactory = null;

sessionFactory = cfg.buildSessionFactory();

both the Configuration and the SessionFactory are stored as private variables in a singleton HibernateUtil class.

in another post, I read that I need to do the following:

Context ctx = new InitialContext();
SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/ArsolHibernateFactory");
sess = factory.openSession();

But I don't quite understand what I need to do to put my session factory into the container and register it under a JNDI name.

Thanks,
-Ben


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