Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Lazy-attributes are null when using loadtime-weaver

På mandag 08. juli 2013 kl. 15:13:41, skrev Tom Ware <tom.ware@xxxxxxxxxx>:
Hi Andreas,

  Here is what we do for LAZY xToOne attributes.  Hopefully we can figure something out.

- When we encounter a LAZY xToOne we weave in a new instance variable called: _persistence_<attributeName>_vh.  It's type is one our proxy objects (we call these ValueHolders).  We also weave in getter and setter methods for the attribute that are used to coordinate the value in the proxy to the value in the actual instance variable.
- When you use FIELD access we change the byte code for GET of that attribute to call the newly weaved getter and the bytecode for PUT to call the newly weaved setter.  We can do this because the JPA specification indicates that direct access to an instance variable from outside of a particular class has undefined behavior.
- When you use property access, we, instead weave the getter and setter for the attribute to coordinate the proxy and the actual value.
- The effect is that when you have traversed a LAZY relationship, the cooresponding instance variable will hold the correct value, but when it is untriggered, the proxy gives a better indication of what the value should be.

I'm not sure what the requirements of your reflection-based, but hopefully we can figure something out to help.
 
What I'm doing is trying to prevent validation of LAZY-mapped associations which are un-initialized, to avoid having to traverse the object-graph and load from DB more than necessary). I'm using the OVal framework (oval.sf.net) for validation, which uses reflection. So, I need to be able to tell the difference between an attribute being null because it isn't initialized yet or because it is initialized and actually is null. I'm using Scala for my entities and field-based access works fine with EL's generated proxies (as opposed to JAVA where I observe the generated proxies are not triggerd on programatically accessed fields). Note that I'm using field-based access without the @Access(AccessType.FIELD), but I assume that is unnecessary when having JPA-mapping-annotations on attributes instead of getters?
 
I'm on holiday with my family now so things will be moving a little slowly but I'll have a look at this more when time permits.
 
Again thanks for your usefull feedback.
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc
 

Back to the top