orm - JPA EclipseLink Weaver generates call to porperty getter inside its setter -> NullPointerException -
i have @embeddable
class uses property access wrap object that's not directly mappable jpa via field access. looks this:
@embeddable @access(accesstype.property) public class mywrapper { @notnull @transient private wrappedtype wrappedfield; protected mywrapper() { } public mywrapper(wrappedtype wrappedfield) { this.wrappedfield = wrappedfield; } @transient public wrappedtype getwrappedfield() { return wrappedfield; } public void setwrappedfield(wrappedtype wrappedfield) { this.wrappedfield = wrappedfield; } @column(name = "wrappedtypecolumn") protected string getjparepresentation() { return wrappedfield.tostring(); } protected void setjparepresentation(string jparepresentation) { wrappedfield = new wrappedtype(jparepresentation); } }
persisting @entity
mywrapper
field works fine. when execute query load entity database, nullpointerexception
. stacktrace , debugging shows eclipselink creates new instance of mywrapper
calling default constructor , calls setjparepresentation()
method (as expected).
but unexpected happens: stacktrace shows getjparepresentation()
called inside setter, of course leads nullpointerexception
when return wrappedfield.tostring()
executed.
java.lang.nullpointerexception @ mywrapper.getjparepresentation(mywrapper.java:27) @ mywrapper.setjparepresentation(mywrapper.java) ... 109 more
fact is, there no call getter in code , stacktrace shows no line number indicating in setter called getter. conclusion be, bytecode weaver of eclipselink generated call getter.
it's easy build workaround, my question is: why eclipselink that?
p.s: i'm using eclipselink 2.3.2.v20111125-r10461 in glassfish server open source edition 3.1.2 (build 23)
when weaving enabled (default on glassfish), eclipselink weave code property get/set methods for,
- change tracking
- fetch groups (partial objects)
- lazy (relationships)
for change tracking support set method weaved check if new value different old value, must call method old value.
now still odd, since building new object, not expect change listener set yet, expect change tracking check bypassed. decompile code see generated.
the easiest fix put in null check in method, best in general code. switch field access, not have issues side-affects in get/set methods. use converter handle conversion, instead of doing conversion in get/set methods.
Comments
Post a Comment