I am having problems with a M:N collection which is defined in a
superclass and inherited by a subclass.  I am using RC5.

Here is my (pseudo-)repository:

    <class-descriptor class="Super">
      <extent-class class-ref="Sub" />

      <field-descriptor name="superKey" column="SUPER_KEY" primarykey="true" />

      <collection-descriptor name="collect"
        element-class-ref="Element"
        indirection-table="INDIRECTION_TABLE">
        <fk-pointing-to-this-class column="SUPER_KEY"/>
        <fk-pointing-to-element-class column="ELEMENT_KEY"/>
      </collection-descriptor>
    </class-descriptor>

    <class-descriptor class="Sub">
      <field-descriptor name="superKey" column="SUPER_KEY" primarykey="true" />

      <collection-descriptor name="collect"
        element-class-ref="Element"
        indirection-table="INDIRECTION_TABLE">
        <fk-pointing-to-this-class column="SUPER_KEY"/>
        <fk-pointing-to-element-class column="ELEMENT_KEY"/>
      </collection-descriptor>
    </class-descriptor>

    <class-descriptor class="Element">
      <field-descriptor name="elementKey" column="ELEMENT_KEY" primarykey="true" />
    </class-descriptor>

When I try to materialize an instance of Sub, I get
ArrayIndexOutOfBoundsException:

java.lang.ArrayIndexOutOfBoundsException: 2
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.getFKQueryMtoN(QueryReferenceBroker.java:626)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.getFKQuery(QueryReferenceBroker.java:574)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollection(QueryReferenceBroker.java:509)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollections(QueryReferenceBroker.java:696)
        at 
org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsIterator.java:492)
        at org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:284)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryReferenceBroker.java:147)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryReferenceBroker.java:244)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryReferenceBroker.java:263)
        at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(PersistenceBrokerImpl.java:997)
        at 
org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(BasePrefetcher.java:153)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker$PBPrefetchingListener.prefetch(QueryReferenceBroker.java:835)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker$PBMaterializationListener.beforeMaterialization(QueryReferenceBroker.java:772)
        at 
org.apache.ojb.broker.accesslayer.IndirectionHandler.beforeMaterialization(IndirectionHandler.java:146)
        at 
org.apache.ojb.broker.accesslayer.IndirectionHandler.materializeSubject(IndirectionHandler.java:332)
        at 
org.apache.ojb.broker.accesslayer.IndirectionHandler.getRealSubject(IndirectionHandler.java:309)
        at 
org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(IndirectionHandler.java:284)
        at $Proxy15.getAccompKey(Unknown Source)
        ...

Looking at the offending line in QueryReferenceBroker, it appears that
itemClassFks has (at least) two entries, while refCld.getPkFields()
has only one.  So it appears that the collection descriptor believes
that it has multiple key fields pointing at Element, while Element
itself has only a single key.  I assume this has to do with the
repeated <fk-pointing-to-element-class> in both Super and Sub.  Is
this true?

Can somebody post a summary of the correct way to deal with inherited
collections and relationships in OJB?

thanks,
-steve

--
Steve Clark
Technology Applications Team
Natural Resources Research Center/USGS
[EMAIL PROTECTED]
(970)226-9291

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to