-->
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: Exceptional Handling in Hibernate
PostPosted: Fri Jul 07, 2006 9:01 am 
Newbie

Joined: Fri Jul 07, 2006 8:04 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

We are planning to migrate to Hibernate from EJB, to remove the application server independency. We are facing issues with exceptional handling, we are not able to find an exact replacement for the EJBException, FinderException, CreateException and other EJB related exceptions.

Can any one please direct me to some article or samples, which will help me in coming up with a conversion strategy.

Thanks & Regards
Muthu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 10:30 am 
Newbie

Joined: Fri Jul 07, 2006 9:53 am
Posts: 11
Here is a skeleton of how we use exception handling with hibernate

the inner try is for the query/insert code. if it gets an error, it will roll the code back to what it was and keep the session alive. If the outter try fails, then you can narrow down you have something wrong with your session handlers. Hope it helps.


try {
Session sqlSession = HibernateUtil.currentSession();
Transaction tx = null;

try {
tx = sqlSession.beginTransaction();
[query stuff]
tx.commit();

} catch (HibernateException he) {
logger.error(he.getMessage());
if (tx != null) {
logger.error("Initiating rollback");
tx.rollback();
}
throw he;
} finally {
logger.debug("Closing Session");
HibernateUtil.closeSession();
}
} catch (HibernateException he) {
logger.error(he.getMessage());
logger.error(BaseForm.stackTraceToString(he));
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 12:58 am 
Newbie

Joined: Fri Jul 07, 2006 8:04 am
Posts: 4
Hi,

Thanks for your reply, but the problem I am facing is that, in our application (current application is developed in EJB, we are trying to port it to Hibernate now) we are trying to replace the existing exception handling scenario in EJB to Hibernate. For example when we try to create a bean in EJB, we catch the javax.ejb.CreateException and give the error message saying that it’s a duplicate create. Then we will catch the java.ejb.EJBException and say that there was some system error while creating the bean.

Now implementing this code in the Hibernate, we are not able to separate these exceptional scenarios and handle the duplicate creates and other create exception in Hibernate, since we have only one exception thrown in Hibernate, that is HibernateException. This not the only issues, we are also not able to handle the FinderException and EJBException in the finders.

Can any help me out.

Regards,
Muthu


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.