ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Bradley <debrad...@gmail.com>
Subject Can't accurately evaluate null when using proxies?
Date Wed, 21 Sep 2005 18:15:18 GMT
I'm running into odd conditions, apparently because of the way iBATIS
uses CGLIB for proxying and I'm wondering if it's just something I'm
doing wrong or if there's a workaround.

While an entity may *appear* to return null from a getter (null is
actually the proxied result), (entity.getFoo() == null) surprisingly
evaluates to false, because getFoo() returns the proxy, which is
non-null, not the proxied result.

Some sample code may make this a little clearer:

// Entity has a relation to Foo, which may be null - foo is lazily loaded
Entity entity = dao.getById(1);

// In the debugger the following evaluates to Foo$$EnhancerByCGLIB$$12345678
// with a value of null:

// And then...
entity.getFoo() == null; // ...evaluates to false!

// And so does this:
Foo foo = entity.getFoo();
foo == null; // false

Is my approach wrong? Is there a way around it, other than not using
lazy loading? Thanks for any help.

View raw message