-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-to-many to subclass returning null using property-ref
PostPosted: Thu Sep 21, 2006 4:11 am 
Newbie

Joined: Thu Sep 21, 2006 2:02 am
Posts: 1
Hibernate version: 3.1.3
DB: Oracle 10.1.0.3.0
JDBC Driver: 10.2.0.2

Problem:
I have a many-to-many pointing to a subclass trying to load a bi-directional one-to-one via property-ref.

Mapping file, many-to-one unique
Code:
<hibernate-mapping>
  <class table="T_DOCUMENT" name="Document">
    <id column="ID" name="id">
      <generator class="sequence">
        <param name="sequence">T_Document_ID_SEQ</param>
      </generator>
    </id>
    <many-to-one not-null="true" unique="true" column="classification_id" lazy="false" cascade="save-update" name="classification" class="DocClassification"/>
  </class>
</hibernate-mapping>


Mapping file, subclass with one end of the many-to-many and a one-to-one using property-ref(for simplicity reasons, I only post one subclass)
Code:
<hibernate-mapping>
  <class table="T_CLASSIFICATION" name="Classification">
    <id column="ID" name="id">
      <generator class="sequence">
        <param name="sequence">T_Classification_ID_SEQ</param>
      </generator>
    </id>
    <discriminator type="string" column="type_string"/>
    <bag table="T_OBJECT_CLASSIFICATION" access="field" lazy="false" name="classificationValues">
      <key column="classification_id"/>
      <many-to-many column="classification_value_id" class="ClassificationValue"/>
    </bag>
    <subclass name="DocClassification" discriminator-value="DOCUMENT">
      <one-to-one name="classifiedObject" lazy="false" property-ref="classification" class="Document"/>
    </subclass>
  </class>
</hibernate-mapping>


Mapping file for the other end of the many-to-many
Code:
<hibernate-mapping>
  <class table="T_CLASSIFICATION_VALUE" name="ClassificationValue">
    <id column="ID" name="id">
      <generator class="sequence">
        <param name="sequence">T_Classification_Value_ID_SEQ</param>
      </generator>
    </id>
    <bag table="T_OBJECT_CLASSIFICATION" lazy="false" inverse="true" name="classifications">
      <key column="classification_value_id"/>
      <many-to-many column="classification_id" class="Classification"/>
    </bag>
    <property name="externalIdentifier" column="customer_identifier"/>
  </class>
</hibernate-mapping>



Now, when trying to load a Document, it's Classification (subclass DocClassification) and then all associated ClassificationValues, all works fine.
Going the other way does not. I load a ClassificationValue and get it's list of Classifications. The number of objects is as expected. Asking all of the loaded Classifications for their respective objects returns null in all cases.

To me, this looks like the "one-to-one property-ref" is the problem, but I can't figure out why. The mapping itself to me looks quite similar to the one given in the doc (bidirectional one-to-one association on a foreign key), only obvious difference being the use of subclass.

I've already tried multiple changes to the mappings, e.g. not asking for the actual subclass (DocClassification) but rather the abstract base class (Classification) in the many-to-one in Document.

Changing the many-to-many on the ClassificationValue to the actual subclass (DocClassification instead of Classification) then makes it work. But that does take away the Benefit of using a subclass.

Is there anything wrong in the mapping, a problem with subclassing, etc.?

Or is there another way to map this situation?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.