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

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.

-Tom

On 05/07/2013 6:13 PM, Andreas Joseph Krogh wrote:
Hi.
 
I'm trying out EL on a Scala example-project and it's wired up using Spring with a loadtime-weaver. For lazy-mapped @ManyToOne associations I see that the attribute is null in the debugger but when accessed (field-access in Scala) the null-value is replaced with the actual entity. This is bad for reflection-based validation-frameworks as they only see the null-value.
 
I have then tested a Spring-wired JAVA-project where I only have public attributes in my Entity (no getters and setters) and I observe that also there the lazy-mapped @ManyToOne-attributes are null, even when accessing them programatically. I understand EL generates proxies or something which wraps the fields but this doesn't seem to work for field-access.
 
Is there a way to make reflectoin-based access trigger the generated proxies to work their magic?
 
Thanks.
 
--
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


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top