-->
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: CGLIBLazyInitializer (Proxy) ignores final property methods
PostPosted: Mon Dec 05, 2005 5:09 am 
Newbie

Joined: Wed Jan 05, 2005 6:54 am
Posts: 15
Hi,

Imagine the following class (in Hibernate3 3.1).

Code:
public abstract class LabelledEntity {

  private String label;

  public final String getLabel() {
    return label;
  }

  public final void setLabel(String label) {
    this.label = label;
  }

}


You can "finalize" methods to ensure that an implementing class does not override them.

I found out that, in a many-to-one association referring to implementors of LabelledEntity, accesses to the "Label" property of a many-to-one referred object are not intercepted by the CGLIBLazyInitializer. This is a bit ugly: one may wonder why his "label" is always null even if it has some label value in the database.

Deleting the "final" decoration of the label property is removing this issue.

Just wanted to share my new knowledge. :-)

Regards,

Stefan Schubert


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 5:44 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
"You can "finalize" methods to ensure that an implementing class does not override them"
Proxy overrides methods for interception and final methods can not intercepted ( you ensure that a proxy class does not override and intercept them ).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 5:52 am 
Newbie

Joined: Wed Jan 05, 2005 6:54 am
Posts: 15
baliukas wrote:
Proxy overrides methods for interception and final methods can not intercepted ( you ensure that a proxy class does not override and intercept them ).


This is quite important, isn't it? For developers who are not familiar with Hibernate architecture details it is worth to be added to the documentation that POJOS should never contain any final property accessors if they want those methods to be used by Hibernate.
Even better would be if Hibernate checked for the final marker in accessors on creation of the session factory as Hibernate is knowing exactly whether it uses the proxies or not and therefore it knows the contract it needs to make with the developer (e.g. "don't you use final").

Thanks for your answer!

Stefan Schubert


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 6:03 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
Pvblivs wrote:
baliukas wrote:
Proxy overrides methods for interception and final methods can not intercepted ( you ensure that a proxy class does not override and intercept them ).


This is quite important, isn't it? For developers who are not familiar with Hibernate architecture details it is worth to be added to the documentation that POJOS should never contain any final property accessors if they want those methods to be used by Hibernate.
Even better would be if Hibernate checked for the final marker in accessors on creation of the session factory as Hibernate is knowing exactly whether it uses the proxies or not and therefore it knows the contract it needs to make with the developer (e.g. "don't you use final").


Hibernate 3.1 does check the accessor signature.

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 6:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
As all things important it is already in the docs:

http://www.hibernate.org/hib_docs/v3/re ... pojo-final

and i also think that hibernate logs a warning if there is final methods.

Anything else ? ;)

_________________
Max
Don't forget to rate


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.