Excuse me for my imprecision.
This is an example of my mapping:
Code:
<class name="ClassA" table="CLASS_A">
<id name="id" type="long" column="ID" unsaved-value="null">
<generator class="hilo">
<param name="table">CLASA_HI_VALUE</param>
<param name="column">NEXT_VALUE</param>
<param name="max_lo">100</param>
</generator>
</id>
<property name="name" type="string" column="NAME" not-null="true" />
<property name="description" type="string" column="DESCRIPTION" />
<set name="messages" table="MESSAGES_CLASSA" >
<key column="CLASSA_ID" />
<many-to-many class="Message" column="MESSAGE_ID" />
</set>
<joined-subclass name="ClassB" table="CLASS_B">
<key column="ID" />
<property name="property1" type="string" column="PROPERTY_1" />
<property name="property2" type="int" column="PROPERTY_2" />
</joined-subclass>
<joined-subclass name="ClassC" table="CLASS_C">
<key column="ID" />
<property name="property3" type="string" column="PROPERTY_3" />
<property name="property4" type="int" column="PROPERTY_4" />
<property name="property5" type="int" column="PROPERTY_5" />
<set name="objectSet" inverse="true" cascade="all-delete-orphan" >
<key column="CLASSC_REF" />
<one-to-many class="MyClass" />
</set>
<joined-subclass name="ClassD" table="CLASS_D">
<key column="ID" />
<property name="property6" type="int" column="PROPERTY_6" />
</joined-subclass>
<joined-subclass name="ClassE" table="CLASS_E">
<key column="ID" />
<property name="property7" type="int" column="PROPERTY_7" />
</joined-subclass>
</joined-subclass>
</class>
<class name="MyClass" table="MYCLASS">
<id name="id" type="long" column="ID" unsaved-value="null">
<generator class="hilo">
<param name="table">MYCLASS_ID_HI_VALUE</param>
<param name="column">NEXT_VALUE</param>
<param name="max_lo">100</param>
</generator>
</id>
<many-to-one name="objectClassC" class="ClassC" column="CLASSC_REF" cascade="all" />
<property name="myproperty" type="int" column="MYPROPERTY" />
</class>
As you can see, ClassC has 2 subclasses: ClassD and ClassE.
Moreover, ClassC has a Set of MyClass objects.
This is the code I use to create a ClassD object with a new set of
MyClass objects:
Code:
ClassD obj = new ClassD();
....
....
MyClass myobj = new MyClass();
....
myobj.setObjectClassC(obj);
obj.getObjectSet().add(myobj);
....
tx = sess.beginTransaction();
session.save(obj);
tx.commit();
obj is saved, but doesn' t myobj.
Therefore, in the database obj has an empty set.