2.1:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.oqpc.web.valueobjects"> <class name="ExpNote" table="expnote" discriminator-value="null" lazy="true" polymorphism="explicit" > <id name="expNoteID" column="expNoteID" type="long" > <generator class="identity"/> </id>
<discriminator column="legType" type="string"/>
<property name="explainedID" column="explainedID" type="long"
/> <property name="numPages" column="numPages" type="integer" not-null="false" /> <many-to-one name="file" class="File" column="fileID" cascade="all" unique="true" />
<subclass name="ExpNoteBill" discriminator-value="bill" lazy="true" > <set name="addendums" cascade="save-update" inverse="true" lazy="true"> <key column="expNoteID"/> <one-to-many class="Addendum"/> </set> </subclass>
<subclass name="ExpNoteSL" discriminator-value="sl" lazy="true" > </subclass>
<subclass name="ExpNoteAinc" discriminator-value="ainc" lazy="true" > </subclass>
</class>
</hibernate-mapping>
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.oqpc.web.valueobjects"> <class name="Ainc" table="ainc" > <id name="aincID" type="long" column="aincID" > <generator class="identity"/> </id>
<property name="numPage" column="numPage" type="integer" />
<many-to-one name="bill" class="Bill" column="billID" unique="true" />
<many-to-one name="file" class="File" column="fileID" unique="true" />
<set name="aincExpNotes" cascade="save-update" lazy="true"> <key column="explainedID"/> <one-to-many class="ExpNoteAinc"/> </set>
</class>
<query name="getAincs"><![CDATA[ from Ainc ainc left join fetch ainc.file left join fetch ainc.bill left join fetch ainc.aincExpNotes expNotes left join fetch expNotes.file ]]></query>
</hibernate-mapping> :
mySQL 4:
I've been stuck on this one for a couple of days and it has baffled me and other hibernate users I know. The problem goes like this:
In my hibernate mapping model I have two classes Ainc and ExpNote. I've listed the mapping docs below. ExpNotes has three subclasses ExpNoteAinc, ExpNoteBill, ExpNoteSL. There is a one-to-many relationship between Ainc and ExpNotesAinc. However when I retrieve the set of aincExpNotes I get all ExpNotes when I only wanted ExpNoteAinc objects. In Ainc.hbm.xml I've mapped the set as:
<set name="aincExpNotes" cascade="save-update" lazy="true">
<key column="explainedID"/>
<one-to-many class="ExpNoteAinc"/>
</set>
Which has spedified class="ExpNoteAinc", but it seems that the set is still not being limited to the subclass. I've read Hibernate in Action and this seems to be the suggested way to do this. Can you see anything wrong with my mapping that is causing all ExpNote objects (the parent class) to be returned instead of just the subclass ExpNoteAinc objects.
|