Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ManyToMany Virtual Map in Moxy for inheritance(Virtual Relation with inheritance in Moxy seems not working correctly.)
icon4.gif  ManyToMany Virtual Map in Moxy for inheritance [message #1410920] Fri, 22 August 2014 00:36 Go to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I have a Virtual Mapping like this
<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.dynamic.model.generated">
   <java-types>
<java-type name="FxUser" super-type="com.flexdms.flexims.dynamic.model.generated.FxRole">
         <xml-root-element name="FxUser"/>
         <xml-virtual-access-methods/>
         <java-attributes/>
      </java-type>
	  <java-type name="FxRole" >
         <xml-root-element name="FxRole"/>
         <xml-virtual-access-methods/>
         <java-attributes>
            <xml-element java-attribute="fxversion" name="fxversion" type="java.sql.Timestamp"/>
            <xml-element java-attribute="Name" name="Name" type="java.lang.String"/>
            <xml-element java-attribute="id" name="id" type="java.lang.Long" xml-id="true"/>
            <xml-element java-attribute="Description" name="Description" type="java.lang.String"/>
            <xml-element java-attribute="SubRole" name="SubRole" container-type="java.util.List" type="com.flexdms.flexims.dynamic.model.generated.FxRole" xml-idref="true"/>
            <xml-element java-attribute="IncludedBy" name="IncludedBy" container-type="java.util.List" type="com.flexdms.flexims.dynamic.model.generated.FxRole" xml-idref="true"/>
         </java-attributes>
      </java-type>
</xml-bindings>

My Xml Input is like this
<?xml version="1.0" encoding="UTF-8"?>
<FxRole> <id>901</id><fxversion>2014-05-29T10:46:08.36227-07:00</fxversion> <Name>Test1</Name><SubRole>61</SubRole>
</FxRole>


I set up ID Resolver to load the FxRole(id=61) or FxUser(id=61) from database when it is requested by Unmarhsaller.
My test case tests the SubRole's size is one when this xml is unmarshalled.
But I run my test case, it worked only occasionally. Most of time it failed. But It indeed worked sometime.

I traced it down to org.eclipse.persistence.internal.oxm.ReferenceResolver
 line 90:  private void createPKVectorsFromMap(Reference reference, CollectionReferenceMapping mapping) {
        CoreDescriptor referenceDescriptor = mapping.getReferenceDescriptor();
        Vector pks = new Vector();
        if(null == referenceDescriptor) {
            CacheId pkVals = (CacheId) reference.getPrimaryKeyMap().get(null);
            if(null == pkVals) {
                return;
            }
            for(int x=0;x<pkVals.getPrimaryKey().length; x++) {
                Object[] values = new Object[1];
                values[0] = pkVals.getPrimaryKey()[x];
                pks.add(new CacheId(values));
            }
        } else{ 
            List pkFields = referenceDescriptor.getPrimaryKeyFieldNames();
            if (pkFields.isEmpty()) {
                return;
            }

            boolean init = true;

            // for each primary key field name
            for (Iterator pkFieldNameIt = pkFields.iterator(); pkFieldNameIt.hasNext(); ) {
line 113:               CacheId pkVals = (CacheId) reference.getPrimaryKeyMap().get(pkFieldNameIt.next());
                if (pkVals == null) {
                    return;
                }
                // initialize the list of pk vectors once and only once
                if (init) {
                    for (int i=0; i<pkVals.getPrimaryKey().length; i++) {
                        pks.add(new CacheId(new Object[0]));
                    }
                    init = false;
                }

                // now add each value for the current target key to it's own vector
                for (int i=0; i<pkVals.getPrimaryKey().length; i++) {
                    Object val = pkVals.getPrimaryKey()[i];
                    ((CacheId)pks.get(i)).add(val);
                }
            }
        }
        reference.setPrimaryKey(pks);
    }


Notice line 113(marked): pkFieldNameIt.next() gives FxUser.id/text() most of time while reference.getPrimaryKeyMap() has only one key "id/text()". so pkVals==null and my ID Resolver is never called at later time.

I tried various workaround and could not get it worked. In Xml-binding, I specified the SubRoles's type is FxRole, how could the the pkFieldName be set to Fxuser.id/text()?

I already spent on several days on this and could not get it worked. Any suggestion is really appreciated.

-jason
Re: ManyToMany Virtual Map in Moxy for inheritance [message #1412251 is a reply to message #1410920] Mon, 25 August 2014 17:06 Go to previous message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
Finally, have a workaround after several days debugging.
The problem is that in other part of oxm.xml, I have an type like this
 <java-type name="FxUserSettings" super-type="com.flexdms.flexims.jpa.eclipselink.FleximsDynamicEntityImpl">
         <xml-root-element name="FxUserSettings"/>
         <xml-virtual-access-methods/>
         <java-attributes>
            <xml-element java-attribute="FxUser" name="FxUser" type="com.flexdms.flexims.dynamic.model.generated.FxUser" xml-idref="true"/>
         </java-attributes>
      </java-type>

Here this type refers to FxUser. If I change the target type to super type with xml-id element com.flexdms.flexims.dynamic.model.generated.FxRole instead of com.flexdms.flexims.dynamic.model.generated.FxUser, whole process works.


Previous Topic:EclipseLink 2.5.2 is returning empty vector with size 1 with getResultList
Next Topic:Generating Metadata using M2E
Goto Forum:
  


Current Time: Fri May 29 08:33:42 GMT 2015

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

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