-->
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: Catching exceptions when using getCurrentSession
PostPosted: Fri Jun 10, 2005 11:34 am 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
Hibernate version: 3.0.3

I just discovered SessionFactory.getCurrentSession() today. Sweet! :) This obsoletes the JBoss/Hibernate integration code that I copy-pasted and patched-up to work with Hibernate 3. One of the features that I added to that code that I can't seem to find in Hibernate is the ability to catch an exception that is thrown from the JTA Synchronization. For instance, if session.flush() throws a HibernateException, how do I catch it? The flush call is happening outside of my code now.

In my integration code, I added an ExceptionHandler interface, which I passed as an optional parameter when getting the managed session. Would this make sense to add to Hibernate's integration code? Something like SessionFactory.getCurrentSession(ExceptionHandler handler)? I'm working on implementing this right now, but if there's some other way that already exists in the code base to do this, I thought it was worth posting and asking.

Thanks.
--Tim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 6:13 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
So, in case anyone out there on the forums is listening or cares, I went ahead and added this ability to Hibernate. I tried to create an issue in JIRA and submit a patch, but every time I try to submit it, JIRA says
"# Form Errors: Exception: java.lang.reflect.UndeclaredThrowableException"

Nice. Anyway, I'll try again later if I can remember. Otherwise, if anyone wants the patch, send me an e-mail and I'll be happy to send it to you. I basically added a method to Session called addManagedExceptionHandler.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 6:16 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
I'm pasting the text that I wrote up in the JIRA issue that won't seem to work in case I feel like trying it again later.

I wrote up my original question at http://forum.hibernate.org/viewtopic.php?p=2246120 but basically once I discovered getCurrentSession(), I went to scrap our JBoss-Hibernate JTA glue code, but the piece that was missing from Hibernate's version is the ability to catch exceptions that are throw from flush() and close(). I'm attaching a patch that lets the user do this. It basically goes like this:

Session session = factory.getCurrentSession();
session.addManagedExceptionHandler(handler);

where the handler just implements the method:

void handleHibernateException(RuntimeException e)

This is needed because when using getCurrentSession(), flushing and closing the session happens outside of any place that the user can wrap in a try block.


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.