views:

330

answers:

1

hi all, i got a complicate mapping, i think it suppose to work...but why it compile A.d column is not existed???

public abstract Class A {
private Integer Id;
..
...
}

public Class SubA extend A {
   private D d;
}

public Class D {
   private SubA subA;
}

A.hbm.xml
<class name="A" table="A" abstract="true"/>

...

<subclass 
        name="SubA" 
        discriminator-value="SUB_A"
        lazy="false"
    >
        <join table="TABLE_SUB_A">
                <key column="ID"/>

            <many-to-one name="d" 
     column="COL_D" 
                class="D"
                cascade="NONE"
                outer-join="true"
                unique="true"/>
        </join>
   </subclass>
   </class>

D.hbm.xml
<one-to-one name="subA"
   class="SubA"
   property-ref="d"/>
A: 

Your code doesn't show discriminator column definition in A class, I'm assuming it's there. Also there's no "outer-join" attribute; it should be fetch="outer-join" instead.

Other then that, though, it looks OK - d property should be looked up on subA, not A. Are you sure you haven't changed anything when you've posted (I don't think you real entities are called A and D, so double check that you mapping is indeed as shown).

Also, why are you using discriminator for table-per-subclass? Using joined-subclass makes for easier mapping with no superfluous columns; the only advantage of discriminator is avoiding outer join on subclass tables which is usually not a big deal (plus you haven't specified fetch="select" on your subclass anyway)

ChssPly76