-->
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.  [ 2 posts ] 
Author Message
 Post subject: CGLIBLazyInitializer and Exceptions
PostPosted: Sun Aug 28, 2005 3:10 pm 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hibernate version:3.0.5

Hi everybody!

I am using many-to-one association with lazy loading enabled (default option in Hibernate 3). As a result, all references to classes which are mapped trough this association are proxied, which is good.

What bad (at least for me) is, when proxied object's method throws an exception, this exception will arrive as InvocationTargetException instead of original which I would expect.

For example consider the following model:

Code:
class A {

  B b; //This one is mapped as many-to-one association

  setB(B b) {
     this.b = b;
  }

  getB() {
     return b;
  } 
}

class B {
   public void foo() throws MyException {
       throw new MyException();
   }
}

class MyException extends Exception {
}


When I'll call a.getB().foo() there will be 2 different behaviors:

1. If lazy loading is disabled, I'll get MyException.
2. If lazy loading is enabled, I'll get InvocationTargetException.

The second one is very dangerous. It bypasses type checking (MyException is NOT a RuntimeException) and causes unpredicted behavior.

CGLIBLazyInitializer could easily catch an InvocationTargetException, and rethrow it's cause.

What do you think? Or am I missing something?

Thanks a lot!
Michael.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 2:31 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
register it in JIRA, this is a bug.


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