Does a final method prevent Hibernate from creating a proxy for such an entity? -



Does a final method prevent Hibernate from creating a proxy for such an entity? -

hibernate uses proxies enable lazy loading of collections , single-ended associations. according hibernate's (3.6.5) reference documentaion (section 21.1.3, single-ended association proxies), such proxy can't constructed hibernate if contains "any final methods". question is, restriction apply getters/setters of persistent fields or method in entity class? so, method one:

public final string tostring() { homecoming this.getclass().getsimplename() + id; }

really prevent creation of (cglib or javassist) proxy entity? matter if field-based or property access used? since cglib replaced javassist, provide more features in direction?

i utilize inheritance in entity hierarchy , hence requirement define final methods, example, in base of operations class prevent subclasses overriding methods.

thanks in advance!

by help of hibernate mailing list (thanks emmanuel bernardt!) i'm able reply own question, summary is: final methods not prevent hibernate creating proxy in general unless methods don't utilize any state of entity highly inadvisable.

some background information: hibernate doesn't utilize bytecode enhancement neither cglib nor javassist so, in order proxy initialize target entity lazily has intercept method may utilize state of target entity. it's ok have final method this

public final dosomething(string a, integer b ) { // complicated stuff using , b (no instance members accessed!) }

but method uses persistent field straight or through instance method bypass proxy , lead unexpected behaviour.

as sidenote same reason why should not access fields of other instances directly, illustration in entities equals method:

// xxx bad code! public boolean equals(object o) { if (this == o) homecoming true; if (!(o instanceof profile)) homecoming false; profile profile = (profile) o; // xxx bypasses possible proxy, utilize profile.getname() instead! homecoming (name == null ? profile.name == null : name.equals(profile.name)); }

hibernate

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -