Dynamic Moxy can not work together with JPA Lazy Loading [message #1107026] |
Wed, 11 September 2013 18:06  |
Eclipse User |
|
|
|
In my application, I use DynamicEntity for JPA. So the DynamicEntity is from JPA, not from moxy. The relationship is lazy-loaded. The actual value is ValueHolder. ValueHodler is transparent to application. But when the DynamicEntity is passed to moxy for marshalling, it gives error.
I traced it to
Object targetObject = marshalContext.getAttributeValue(object, xmlObjectReferenceMapping).
The marshalContext here is ObjectMarshalContext. The retrieved value (TargetObject) is UnitOfWorkValueHolderImpl. DynamicJaxB treats UnitOfWorkValueHolderImpl as domain object.
This is definitely a bug. Should I file a bug for this? At the same time, is there any workaround for this?
thanks
|
|
|
|
Re: Dynamic Moxy can not work together with JPA Lazy Loading [message #1107243 is a reply to message #1107111] |
Thu, 12 September 2013 02:11  |
Eclipse User |
|
|
|
I work around this using virtual access mapping.
First I have my own DynamicEntityImpl
@XmlTransient
@XmlVirtualAccessMethods(getMethod="realGet", setMethod="realSet")
public abstract class FleximsDynamicEntityImpl extends DynamicEntityImpl
{
public Object realGet(String propertyName)
{
return this.get(propertyName);
}
public void realSet(String propertyName, Object value)
{
super.set(propertyName, value);
}
}
Second I set the super-type of this class to java.lang.Object so that DynamicEntityImpl will not be scanned.
<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
xml-accessor-type="NONE"
xml-mapping-metadata-complete="true" package-name="com.flexdms.flexims.typedb.eclipselink">
<xml-schema attribute-form-default="UNQUALIFIED" element-form-default="UNQUALIFIED" namespace="http://www.flexdms.flexims/instance">
<xml-ns namespace-uri="http://www.w3.org/2001/XMLSchema" prefix="xsd"/>
</xml-schema>
<java-types>
<java-type name="FleximsDynamicEntityImpl" super-type="java.lang.Object" xml-accessor-type="NONE">
</java-type>
</java-types>
</xml-bindings>
Finally I have bindings for my Dynamic Class. All of my Dynamic Class will be subclasses of FleximsDynamicEntityImpl.
<java-type name="SingleInt">
<xml-root-element name="SingleInt"/>
<xml-virtual-access-methods get-method="realGet" set-method="realSet"/>
<java-attributes>
<xml-attribute java-attribute="id" name="id" xml-id="true" type="java.lang.Long"/>
<xml-element java-attribute="DateCreated" name="DateCreated" required="true" type="java.sql.Timestamp"/>
<xml-element java-attribute="DateModified" name="DateModified" required="true" type="java.sql.Timestamp"/>
</java-attributes>
</java-type>
I tested marshall. I have not tested unmarshal yet.
|
|
|
Powered by
FUDForum. Page generated in 0.04107 seconds