Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Dynamic Moxy can not work together with JPA Lazy Loading
Dynamic Moxy can not work together with JPA Lazy Loading [message #1107026] Wed, 11 September 2013 22:06 Go to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
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 #1107111 is a reply to message #1107026] Thu, 12 September 2013 01:20 Go to previous messageGo to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I am trying to use VirtualMapping as a workaround. I do not need DynamicJaxbContext to control my entity since entity is already created by JPA.

Here is an example mapping
<java-type name="SingleInt" super-type="java.lang.Object" xml-accessor-type="PUBLIC_MEMBER">
         <xml-root-element name="SingleInt"/>
         <xml-virtual-access-methods get-method="realGet" set-method="set"/>
         <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"/>
            <xml-element java-attribute="defaultCase" name="defaultCase" type="java.lang.Long"/>
            <xml-element java-attribute="withdefault" name="withdefault" type="java.lang.Long"/>
            <xml-element java-attribute="requiredAndAuto" name="requiredAndAuto" required="true" type="java.lang.Long"/>
            <xml-element java-attribute="AutoButNotRequired" name="AutoButNotRequired" type="java.lang.Long"/>
            <xml-element java-attribute="withminandmax" name="withminandmax" type="java.lang.Integer"/>
            <xml-element java-attribute="allowedValue" name="allowedValue" type="java.lang.Long"/>
            <xml-element java-attribute="allowedWithDefault" name="allowedWithDefault" type="java.lang.Long"/>
         </java-attributes>
      </java-type>



If I specify the super-object is Object, all of my property are skipped by JAXB.
If I do not specify super-type, I got this error no matter xml-accessor-type is PUBLIC_MEMBER or NONE
Exception Description: The class org.eclipse.persistence.internal.dynamic.DynamicEntityImpl$PropertyWrapper requires a zero argument constructor or a specified factory method.  Note that non-static inner classes do not have zero argument constructors and are not supported.



Is there a way I ask the JAXB do not scan my class?

[Updated on: Thu, 12 September 2013 01:21]

Report message to a moderator

Re: Dynamic Moxy can not work together with JPA Lazy Loading [message #1107243 is a reply to message #1107111] Thu, 12 September 2013 06:11 Go to previous message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
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.
Previous Topic:how to control marshaller conditionally?
Next Topic:one-to-many not working with interface
Goto Forum:
  


Current Time: Fri Apr 19 10:08:03 GMT 2024

Powered by FUDForum. Page generated in 0.02004 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top