-->
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.  [ 4 posts ] 
Author Message
 Post subject: proxies, cglib and non-hibernate annotations
PostPosted: Fri Feb 17, 2006 2:49 am 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
I've created a few of my own annotations that my application uses reflectively at runtime. However, when I have a mapped pojo that gets proxied, I lose the ability to discover my annotations because getClass() returns the proxied class type, not the underlying class type.

I've been using Hibernate.getClass(proxiedClass) to work around the issue, but this is starting to introduce Hibernate classes into layers of my application that do not have to be aware of persistence concerns. From my point of view, if hibernate proxies a class, that should not unduly impact the application using that proxied class.

Unfortunately annotations don't have any real inheritence mechanism. Does anyone have any thoughts about this?

One thing that I can think of would be that somehow proxied classes have their annotations copied over during the proxy process.

Any thoughts or pointers are appreciated.

-Erik

P.S. I realize that strictly speaking, this is more a CGLIB and general Hibernate problem and not specific to EJB3/Hibernte Annotations.


Top
 Profile  
 
 Post subject: Re: proxies, cglib and non-hibernate annotations
PostPosted: Fri Feb 17, 2006 5:35 pm 
Newbie

Joined: Wed Jun 30, 2004 2:02 am
Posts: 13
Class annotations can be inherited, but method annotations cannot. This is how Java annotations work.

In our case, there is code that caches annotation information for performance reasons, so there's a handy bottleneck there for me to query for the actual class. I haven't come up with a more elegant solution than that.

As you say, this is more of a CGLIB issue. Seems to me like it might be possible to propagate annotations into the generated class & methods and make the proxying more transparent, but I haven't thought it through all the way.

anders


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 10:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
propagate annotations to subclasses in a generic way is a bad idea IMO.
Usually the annotation reader mechanism goes to the whole hierarchy to find the needed annotations if it makes sense

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 4:40 pm 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
I can understand the point about not using standard inheritence mechanisms to propogate annotations to a subclass.

However, in this case, Hibernate is injecting the subclass using CGLIB. It would be nice if the annotations were copied onto the subclass so client code could continue to use the class transparently.

// is annotation present on ClassXYZ - yes.

// retrieve an instance (InstanceXYZ) of this class from Hibernate

// is annotation present on InstanceXYZ.getClass() - no.

To your point, checking for the presence of an annotation should probably climb the inheritence tree looking for it rather than just blindly assuming the object's class remains unchanged.

So...

A. It would be nice if Hibernate/CGLIB made the proxies behave the same way as the original class with respect to annotiations.

B. Good OO design principles dictact that when looking for annotations, you should climb the class hierarchy anyhow.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.