-->
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: How to get real persistent class from a CGLIB proxy.
PostPosted: Wed May 31, 2006 6:39 am 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
I use EJB3 API.

In a method I receive a Class (not an instance), this class is in fact a proxy class. I need to get the real class (not hte proxy one).

If I writte the classname I have :
class mypackage.ResultPE$$EnhancerByCGLIB$$60a98730

I like to have just
class mypackage.ResultPE

If I had an instance I could use:
HibernateProxyHelper.getClassWithoutInitializingProxy(srcObject)

Unfortunatelly I have only the class.

Any idea on what's available in the API the get the Class from the proxy Class ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 7:59 am 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
It seems that CGLIB enhaced class extends real class. Consequently I can get the real class using clazz.getSuperClass().

How is it possible to know if a class is a real class or an enhanced class ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 1:02 pm 
Newbie

Joined: Tue Mar 01, 2005 6:58 pm
Posts: 7
I have not tested this, but it seams like you could do something like:

Code:
class MyEntity {
  ...
  Class getBaseClass() {
    if (MyEntity.class.equals(getClass()) {
      return getClass();
    } else {
      return getClass().getSuperClass();
    }
  }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 9:06 am 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
I do not want to impact all my persistent enties for such a hook.

I use another solution, I check if classname conatins "$$EnhancerByCGLIB$$". But I'm not happy with that.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
mheath's suggestion is more "portable" than checking for $$EnhancerByCGLIB$$ since the final ejb3 entitymanager will use Javaassist.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 3:29 am 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
I can not change all the persistent classes to add such a method. I need to find a solution that does not impact persistent entities.


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.