-->
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.  [ 6 posts ] 
Author Message
 Post subject: checked HibernateException
PostPosted: Wed Feb 11, 2004 12:33 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.


Somehow, I see it as follows. The problem is that there are many methods to dispatch, i.e. it's boring. A better way, anyone? Thanks

Code:
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;

public class MySessionWrapper {
  private Session hbSession;

  // dispatch ALL 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:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
AOP

_________________
Emmanuel


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

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
emmanuel wrote:
AOP


Am looking for a better solution that DOES NOT involve AOP or Spring. Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I know you don't like this idea but changing HibernateException parent class will solve all your problems, it's not that hard to maintain.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 1:50 pm 
Beginner
Beginner

Joined: Sun Sep 14, 2003 10:54 am
Posts: 36
emmanuel wrote:
I know you don't like this idea but changing HibernateException parent class will solve all your problems, it's not that hard to maintain.


Why not make the change for everyone? I think the issue has been brought up often enough to warrant the change.

It appears that all that needed is to change net.sf.hibernate.exception.NestableException to extend the RuntimeException (or its subclass) instead of the Exception. AFAICT, the change should not even break any of the existing code.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 7:07 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
People may have generic code handling RuntimeException and doing different stuffs with it. So it can break old code.

_________________
Emmanuel


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