Hello,
I have a Class called CAccount whicht is abstract and that has two Childs.
CDAccount and CKAccount. These Two classes are stored in the same Table beeing identified by the Discriminators D and K in the Coulumn disc.
When I load the Classes directly like: Query oQry = oSess.createQuery("FROM baseClasses.CKAccount");
The Application realy only loads the ones with the K in the Coulumn as I expected.
But further on I have two classes called CSupplier and CCustomer.
CSupplier pints with accounts to a set of CKAccount and CCustomer points to a set of CDAccounts. When I now load a Customer or a Supplier, hibernates all accounts disregarding the Discriminator.
My Mappings where the Classes point to each other lookes like this.
Mapping documents:
The Account classes:
Code:
<hibernate-mapping>
<class name="baseClasses.CAccount" table="accounts" >
<id name="id" type="int" column="account_id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">uid_account</param>
</generator>
</id>
<discriminator column="disc" force="true" />
<subclass name="baseClasses.CDAccount" discriminator-value="D">
<many-to-one name="partner" column="partner_id" class="baseClasses.CCustomer" />
</subclass>
<subclass name="baseClasses.CKAccount" discriminator-value="K">
<many-to-one name="partner" column="partner_id" class="baseClasses.CSupplier" />
</subclass>
</class>
</hibernate-mapping>
The Supplier and Customer
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="baseClasses.CPartner" table="partner" discriminator-value="O">
<id name="id" type="int" column="partner_id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">uid_partner</param>
</generator>
</id>
<discriminator column="disc"/>
<property name="name1"/>
<property name="name2"/>
<property name="street"/>
<property name="postcode" type="integer"/>
<property name="city"/>
<property name="country"/>
<property name="telnumber" column="phone"/>
<property name="faxnumber" column="fax"/>
<property name="postbox"/>
<property name="language" type="integer"/>
<property name="memo"/>
<property name="banknumber"/>
<set name="contacts">
<key column="contact_id"/>
<one-to-many class="baseClasses.CContact"/>
</set>
<subclass name="baseClasses.CCustomer" discriminator-value="O">
<set name="accounts">
<key column="partner_id"/>
<one-to-many class="baseClasses.CDAccount"/>
</set>
</subclass>
<subclass name="baseClasses.CSupplier" discriminator-value="O">
<set name="accounts">
<key column="partner_id"/>
<one-to-many class="baseClasses.CKAccount"/>
</set>
</subclass>
</class>
</hibernate-mapping>
Has anyone any idea?
Thanks,
TheAim
Hibernate version: 2.1.7
Database you are using: PostGres 7.4.2