This is my hibernate file that contains all of the mappings for my classes.
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>
<!-- org.teamcharlie.modal.Trigger root -->
<class name="org.teamcharlie.modal.Trigger" table="Trigger">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<property name="state" column="state" type="string"/>
</class>
<!-- org.teamcharlie.modal.Instance root -->
<class name="org.teamcharlie.modal.Instance" table="Instance">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
</class>
<!-- org.teamcharlie.modal.CIMMethod root -->
<class name="org.teamcharlie.modal.CIMMethod" table="Method">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="overRiddenMethod" column="overRiddenMethod" class="org.teamcharlie.modal.CIMMethod"/>
<property name="methodName" column="methodName" type="string"/>
<property name="returnType" column="returnType" type="string"/>
<array name="triggers" table="Triggers" cascade="all">
<key column="uid_triggers"/>
<index column="idx_triggers"/>
<one-to-many class="org.teamcharlie.modal.Trigger"/>
</array>
<array name="parameters" table="Parameters" cascade="all">
<key column="uid_parameters"/>
<index column="idx_parameters"/>
<element column="elm" type="string"/>
</array>
</class>
<!-- org.teamcharlie.modal.NamedElement root -->
<class name="org.teamcharlie.modal.NamedElement" table="NamedElement">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<array name="qualifiers" table="Qualifier" cascade="all">
<key column="uid_qualifiers"/>
<index column="idx_qualifiers"/>
<one-to-many class="org.teamcharlie.modal.Qualifier"/>
</array>
</class>
<!-- org.teamcharlie.modal.Property root -->
<class name="org.teamcharlie.modal.Property" table="Property">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<many-to-one name="overridenProperty" column="overridenProperty" class="org.teamcharlie.modal.Property"/>
<array name="triggers" table="Trigger" cascade="all">
<key column="uid_triggers"/>
<index column="idx_triggers"/>
<one-to-many class="org.teamcharlie.modal.Trigger"/>
</array>
<property name="type" column="type" type="string"/>
<array name="qualifiers" table="qualifiers" cascade="all">
<key column="uid_qualifiers"/>
<index column="idx_qualifiers"/>
<one-to-many class="org.teamcharlie.modal.Qualifier"/>
</array>
<property name="value" column="value" type="string"/>
</class>
<!-- org.teamcharlie.modal.Qualifier root -->
<class name="org.teamcharlie.modal.Qualifier" table="Qualifier">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="defaultValue" column="defaultValue" type="string"/>
<property name="flavor" column="flavor" type="string"/>
<property name="name" column="name" type="string"/>
<property name="scope" column="scope" type="string"/>
<many-to-one name="type" class="org.teamcharlie.modal.QualifierType"/>
<property name="value" column="value" type="string"/>
</class>
<!-- org.teamcharlie.modal.QualifierType root -->
<class name="org.teamcharlie.modal.QualifierType" table="QualifierType">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="type" column="type" type="string"/>
</class>
<!-- org.teamcharlie.modal.Reference root -->
<class name="org.teamcharlie.modal.Reference" table="Reference">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<many-to-one name="overridenProperty" column="overridenProperty" class="org.teamcharlie.modal.Property"/>
<array name="triggers" table="Trigger" cascade="all">
<key column="uid_triggers"/>
<index column="idx_triggers"/>
<one-to-many class="org.teamcharlie.modal.Trigger"/>
</array>
<property name="type" column="type" type="string"/>
<array name="qualifiers" table="qualifiers" cascade="all">
<key column="uid_qualifiers"/>
<index column="idx_qualifiers"/>
<one-to-many class="org.teamcharlie.modal.Qualifier"/>
</array>
<property name="value" column="value" type="string"/>
<many-to-one name="referencedClass" column="referencedClass" class="org.teamcharlie.modal.CIMClass"/>
</class>
<!-- org.teamcharlie.modal.CIMClass root -->
<class name="org.teamcharlie.modal.CIMClass" table="Class">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="version" column="version" type="string"/>
<array name="methods" table="Methods" cascade="all" inverse="true">
<key column="uid_methods"/>
<index column="idx_methods"/>
<one-to-many class="org.teamcharlie.modal.CIMMethod"/>
</array>
<property name="name" column="name" type="string"/>
<array name="properties" table="Property" cascade="all" inverse="true">
<key column="uid_properties"/>
<index column="idx_properties"/>
<one-to-many class="org.teamcharlie.modal.Property"/>
</array>
<array name="triggers" table="Triggers" cascade="all" inverse="true">
<key column="uid_triggers"/>
<index column="idx_triggers"/>
<one-to-many class="org.teamcharlie.modal.Trigger"/>
</array>
<many-to-one name="parentClass" column="parentClass" class="org.teamcharlie.modal.CIMClass"/>
<array name="instances" table="Instances" cascade="all" inverse="true">
<key column="uid_instances"/>
<index column="idx_instances"/>
<one-to-many class="org.teamcharlie.modal.Instance"/>
</array>
<joined-subclass name="org.teamcharlie.modal.Association" table="Association">
<key column="class_id"/>
<array name="references" table="Reference" cascade="all" inverse="true">
<key column="uid_references"/>
<index column="idx_references"/>
<one-to-many class="org.teamcharlie.modal.Reference"/>
</array>
</joined-subclass>
<joined-subclass name="org.teamcharlie.modal.Indication" table="Indication">
<key column="class_id"/>
</joined-subclass>
</class>
<!-- org.teamcharlie.modal.Schema root -->
<class name="org.teamcharlie.modal.Schema" table="Schema">
<id name="id" type="int" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="version" column="version" type="string"/>
<property name="name" column="name" type="string"/>
<array name="classes" table="classes" cascade="all">
<key column="uid"/>
<index column="idx"/>
<one-to-many class="org.teamcharlie.modal.CIMClass"/>
</array>
</class>
</hibernate-mapping>
In a JUnit test, using cactus I run the following setup to add 3 temporary objects to my database.
Code:
super.setUp();
//this sesion of code cleans up the database
Session session = HibernateSession.getInstance().getSession();
//Add A, B, and C to the database
CIMClass A = new CIMClass();
A.setName("A");
A.setVersion("1");
A.setProperties(
new Property[]{
new Property(0, "A prop1", "String", "", null, null, null),
new Property(0, "A prop2", "String", "", null, null, null)
}
);
A.setMethods(
new CIMMethod[]{
new CIMMethod(0, "A method1", "void", new String[]{"param1", "param2"}, null, null),
new CIMMethod(0, "A method2", "void", new String[]{"param1", "param2"}, null, null)
}
);
A.setInstances(new Instance[]{new Instance(0, "A instance")});
CIMClass B = new CIMClass();
B.setName("B");
B.setVersion("1");
//set the parent class to A
B.setParentClass(A);
B.setProperties(
new Property[]{
new Property(0, "B prop1", "String", "", null, null, null),
new Property(0, "B prop2", "String", "", null, null, null)
}
);
B.setMethods(
new CIMMethod[]{
new CIMMethod(0, "B method1", "void", new String[]{"param1", "param2"}, null, null),
new CIMMethod(0, "B method2", "void", new String[]{"param1", "param2"}, null, null)
}
);
B.setInstances(new Instance[]{new Instance(0, "A instance")});
CIMClass C = new CIMClass();
C.setName("C");
C.setVersion("1");
//Set parent Class
C.setParentClass(A);
C.setProperties(
new Property[]{
new Property(0, "C prop1", "String", "", null, null, null),
new Property(0, "C prop2", "String", "", null, null, null)
}
);
C.setMethods(
new CIMMethod[]{
new CIMMethod(0, "C method1", "void", new String[]{"param1", "param2"}, null, null),
new CIMMethod(0, "C method2", "void", new String[]{"param1", "param2"}, null, null)
}
);
C.setInstances(
new Instance[]{
new Instance(0, "C instance 1"),
new Instance(0, "C instance 1")
});
//save them in the databse
session.save(A);
session.save(B);
session.save(C);
session.flush();
session.close();
Hoever, when I look in the database, the key column is null for all of the child object arrays of the CIMClass. For instance, the Class table has the row.
Code:
'id','version','name','parentClass','uid','idx'
'16','1','A','[NULL]','[NULL]','[NULL]'
And these are two rows in the method table
Code:
'id','overRiddenMethod','methodName','returnType','uid_methods','idx_methods'
'31','[NULL]','A method1','void','[NULL]','[NULL]'
'32','[NULL]','A method2','void','[NULL]','[NULL]'
As you can see, the uid_methods property never gets set to the value of class.id. However when I delete the objects, all child objects in the array are deleted as well. Does anyone have any clue as to why this is happening or how to fix it?
Thanks,
Todd.