-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Exception Handling
PostPosted: Fri Sep 14, 2007 10:05 am 
Newbie

Joined: Fri Sep 14, 2007 9:41 am
Posts: 8
Hi all,
I've been having some trouble trying to solve this and looked over the internet but couldn't find a reasonable way to do it. The thing is I'm trying to handle exceptions thrown by Hibernate.
What happen is:
In a simple case I have two servlets chained that when the first finishes its processing it calls the second one.That works fine when no exception occurs, but when one do happen it throws a 500 error on my servers. That is also fine, so I use a try/catch block around the method call that uses Hibernate to access the database.

So, when the exception occurs I do set a error message to my request and rollback the transaction using an Hibernate Helper.
Code:
try{
dataBaseUpdateMethodCall();
}catch(HibernateException he){
    request.setAttribute("message","Error xyz");
    HHelperClass.getCurrentSession().getTransaction().rollback();
}
RequestDispatcher rd = request.getRequestDispatcher("/otherServlet.db");
rd.foward(request,response):


Well, here it does catch and rollback the transaction and moves to the other servlet, but no other hibernate session is created, so in the next servlet where I also do some other dataBaseMethodCalls Hibernate throws others exceptions saying that there is no session.

So, what should I do to catch Hibernate Exceptions handles this errors and pass a accurate message to my user? Thanks in advance...


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

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.