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...