[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 05:44:17 EDT 2011
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)
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.
On 08.07.2011, at 11:26, Emmanuel Bernard wrote:
> If your toString method ends up calling some of the entity state (likely), the initialization won't be triggered since you will call your getters from inside the instance. So it's a good general rule to mandate non final methods on entities.
>
> Emmanuel
>
> On 8 juil. 2011, at 09:59, Robin Sander wrote:
>
>>
>> Hi all,
>>
>> excuse me if this list isn't indented for such a question, but I asked this question about a year ago in the forums
>> without any answers and I think it should be easy to answer for any Hibernate core developer:
>>
>> According to Hibernate's (3.6.5) reference documentaion (Section 21.1.3, Single-ended association proxies),
>> such a single-ended association proxy can't be constructed by Hibernate if it contains "any final methods".
>>
>> My question is, does this restriction apply to getters/setters of persistent fields only or really to any method in an entity class?
>> As far as I can see Javassist is able to modify final methods as well and even if it were not, why should a method like
>> public final String toString() {
>> return "...";
>> }
>> prevent Hibernate from using a proxy?
>>
>> Thanks in advance,
>>
>> Robin.
>>
>>
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>
More information about the hibernate-dev
mailing list