Here is a mapping file, which describes the hierarchy of two classes
Code:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="prkm.wssup.db.persistance">
<class name="JarObject" table="jar_object">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<discriminator column="service_jar" type="string" />
<property name="jarName" column="jar_name" type="string" not-null="true" />
<property name="originName" column="origin_name" type="string" not-null="true" />
<property name="description" column="description" type="string" not-null="false" />
<many-to-one name="user" column="user_id" class="User" not-null="true" lazy="false"/>
<!--Service class-->
<subclass name="ServiceJarObject" discriminator-value="SRV">
<set name="jarDepenededObjSet" cascade="save-update" lazy="true" >
<key column="service_jar_id"/>
<many-to-many class="LoadJarObject" column="load_jar_id"/>
</set>
</subclass>
<!--Load class-->
<subclass name="LoadJarObject" discriminator-value="LOAD">
<set name="jarDepenededObjSet" cascade="save-update" lazy="true">
<key column="load_jar_id"/>
<many-to-many class="ServiceJarObject" column="service_jar_id"/>
</set>
</subclass>
</class>
</hibernate-mapping>
The objects are stored into the DB correctly, it mean that for each subclass is written its discriminator. The problems start when i load the objects from Db. For example, when i load the LoadJarObject objects, I recieve all records from table as LoadJarObject objects.
The SQL belove: the first - when i get all ServiceJarObject, and the second - LoadJarObject
Code:
Hibernate: select servicejar0_.user_id as user6_1_, servicejar0_.id as id1_, servicejar0_.id as id14_0_, servicejar0_.jar_name as jar3_14_0_, servicejar0_.origin_name as origin4_14_0_, servicejar0_.description as descript5_14_0_, servicejar0_.user_id as user6_14_0_ from jar_object servicejar0_ where servicejar0_.user_id=?
Hibernate: select loadjarobj0_.user_id as user6_1_, loadjarobj0_.id as id1_, loadjarobj0_.id as id14_0_, loadjarobj0_.jar_name as jar3_14_0_, loadjarobj0_.origin_name as origin4_14_0_, loadjarobj0_.description as descript5_14_0_, loadjarobj0_.user_id as user6_14_0_ from jar_object loadjarobj0_ where loadjarobj0_.user_id=?
I don't see any discriminators in the generated by Hibenate SQL. :-(
Can anybody help me? Thank you.[/code]