-->
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.  [ 5 posts ] 
Author Message
 Post subject: HibernateException
PostPosted: Sun Oct 26, 2003 4:58 pm 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
Hello,

I am involved in a project where I would like to use Hibernate. What bothers me is that before we started talking about persistance implementation details we kind of agreed that the component interfaces should only throw checked BusinessExceptions and all technical problems should be communicated via RuntimeExceptions. Now that HibernateException is not a RuntimeException, this forces me to surround evey call to Hibernate with a try/catch block and wrap a possible HibernateException inside some RuntimeException. What I would like more is that HibernateException extended some RuntimeException so that I wouldn't need all this try/catch/wrap code.

I was wondering if this has been discussed before or has anyone come up with any other clever solutiuons to this kind of situation?

I also looked at HibernateException code and saw that it would be very easy just for my project to change 'extends NestableException' to 'extends NestableRuntimeException' which is also available in the org.apache.commons.lang.exception package with a similar interface. Do you think this would cause any problems?

best regards,
Erik J


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 26, 2003 5:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, this has been discussed before and it is my view that this was a mistake in the design of Hibernate.

Unfortunately changing now has the potential to break existing code, so we are stuck with it.

However, it is VERY easy to write a wrapper for the Hibernate Session that converts exceptions, or to use a fwk like Spring that does this.

Alternatively, you could work with your own locally patched version of Hibernate (aaahh the beauty of opensource).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 26, 2003 5:49 pm 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
thanks Gavin for the quick reply,

I am glad that we are not going in the wrong direction with our design and other people have discussed this before.

I will look into Spring as to how it can help us or maybe settle for a wrapper for Session because I am not that fond of patching every new release of Hibernate.

best regards,
Erik J


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:43 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
gavin wrote:
However, it is VERY easy to write a wrapper for the Hibernate Session that converts exceptions, or to use a fwk like Spring that does this.


Can you clarify how you see it done? Somehow, I see it as follows. A better way? Thanks

Code:
public class MySessionWrapper {
  private Session hbSession;

  // dispatch [b]ALL[/b] hbSession methods as follows
  public Transaction beginTransaction() {
    try {
         return hbSession.beginTransaction();
    } catch (Exception e) {
         throw new RuntimeException("Whatever ...");
    }
    ....
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:35 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
Please see http://forum.hibernate.org/viewtopic.ph ... 23#2189723


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