[hibernate-dev] Still true with Javassist? Any final method prevents Hibernate from creating single-ended association proxies

Robin Sander robin.sander at gmx.net
Fri Jul 8 06:45:37 EDT 2011


Many thanks for your answers! To sum this up:
Final methods don't prevent Hibernate from creating a proxy in general but unless those methods
don't use any state of the entity this is highly inadvisable.

Since I have several methods in base classes which indeed don't use any entity state this is good news for me.

So this boils down whether a final method can be intercepted or not. But isn't Javassist capable of doing so?
And if that's true, are there any plans to support intercepting final methods as well?


On 08.07.2011, at 12:11, Emmanuel Bernard wrote:

> 
> On 8 juil. 2011, at 11:44, Robin Sander wrote:
> 
>> 
>> Isn't that totally independent from a method beeing final or not?
>> If I have a method:
>> 
>> public int getSum() {
>> return field1 + field2;
>> }
>> 
>> Then this would trigger the initialization of the entity (in JavassistLazyInitializer I assume)
>> and 
>> 
>> public final int getSum() {
>> return field1 + field2;
>> }
>> 
>> would not? (if field1 and field2 are persistent fields and field-based access is used)
> 
> correct. we can't intercept a final method and thus can't initialize when you call getSum()
> 
>> 
>> Only yesterday I've stumpled upon a related issue in equals(): I've compared a persistent field of two instances
>> of the same entity and that _did not_ trigger the initialization of the other instance proxy. So there I had to use
>> "If (this.field.equals(other.getField())) { ..."  instead of If (this.field.equals(other.field)) { ..."
>> and no method of that entity was final.
> 
> Not the same but related. you are bypassing the proxy and thus don't initialize.
> 





More information about the hibernate-dev mailing list