I hope this is a simple issue.
I have a parent (Summary) and a child (Result)
Hibernate inserts the records into the tables except it doesn't put the parent id in the child's "parent id" column.
if I'm not mistaken, hibernate should put the parent's (Summary) id into the childs (Result) id column, which I have named sid for summary id.
HEre is my summary mapping file, result mapping file and the code I am using to insert. Thanks a lot for your time.
/** Summary (parent) mapping file **/
<?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.apc.qa.ate">
<class
name="Summary"
table="summary"
>
<id
name="Id"
type="integer"
column="Id"
>
<generator class="vm"/>
</id>
<property
name="TestFailed"
column="testFailed"
type="int"
not-null="true"
length="5"
/>
<property
name="Tester"
column="tester"
type="string"
not-null="true"
length="50"
/>
<!-- please tell Joe Hudson that the type 'enum' could not be resolved.. defaulting to java.lang.String -->
<property
name="Sl"
column="sl"
type="java.lang.String"
not-null="true"
length="8"
/>
<property
name="Firmware"
column="firmware"
type="string"
not-null="true"
length="50"
/>
<property
name="TestRun"
column="testRun"
type="int"
not-null="true"
length="5"
/>
<property
name="PowernetMib"
column="powernetMib"
type="string"
not-null="true"
length="50"
/>
<!-- please tell Joe Hudson that the type 'enum' could not be resolved.. defaulting to java.lang.String -->
<property
name="Interface"
column="interface"
type="java.lang.String"
not-null="true"
length="6"
/>
<!-- please tell Joe Hudson that the type 'enum' could not be resolved.. defaulting to java.lang.String -->
<property
name="Category"
column="category"
type="java.lang.String"
not-null="true"
length="16"
/>
<!-- please tell Joe Hudson that the type 'enum' could not be resolved.. defaulting to java.lang.String -->
<property
name="Ssh"
column="ssh"
type="java.lang.String"
not-null="true"
length="8"
/>
<property
name="TestPassed"
column="testPassed"
type="int"
not-null="true"
length="5"
/>
<property
name="TestDate"
column="testDate"
type="timestamp"
not-null="true"
length="19"
/>
<set
inverse="true"
lazy="true"
name="Result"
cascade="all">
<key column="Sid" />
<one-to-many class="Result" />
</set>
</class>
</hibernate-mapping>
/** Result (child) mapping file **/
<?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.apc.qa.ate">
<class
name="Result"
table="result"
>
<id
name="Id"
type="integer"
column="Id"
>
<generator class="vm"/>
</id>
<property
name="Sid"
column="sid"
type="integer"
length="11"
/>
<property
name="Script"
column="script"
type="string"
not-null="true"
length="255"
/>
<!-- please tell Joe Hudson that the type 'enum' could not be resolved.. defaulting to java.lang.String -->
<property
name="Result"
column="result"
type="java.lang.String"
not-null="true"
length="5"
/>
<property
name="Comment"
column="comment"
type="string"
not-null="true"
/>
<many-to-one
name="summary"
class="Summary"
not-null="true"
update="false"
insert="false"
>
<column name="Sid" />
</many-to-one>
</class>
</hibernate-mapping>
/** Code used to insert the records **/
public void setNewRecord() {
try {
_RootDAO.initialize();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Summary p = new Summary();
p.setCategory("Alarm Threshold");
p.setFirmware("105_nairfm");
p.setInterface("http");
p.setPowernetMib("powernet365.mob");
java.util.Date now = new java.util.Date();
p.setTestDate(new java.sql.Timestamp( now.getTime() ));
p.setSsh("disabled");
p.setSl("disabled");
p.setTester(System.getProperty("user.name"));
Result c = new Result();
c.setComment("Test Passed!");
c.setResult("pass");
c.setScript("Number of Modules");
p.setResult(new HashSet());
p.getResult().add(c);
c.setSummary(p);
session.save(p);
session.flush();
session.close();
} catch (HibernateException he) {
System.out.println(he);
}
}
I appreciate anything you can do to help my issue, I'm quite new to hibernate.
Thanks!
|