views:

36

answers:

0

I have 2 tables parent/child which I am trying to insert records in. ParentID is a surrogate key in child table. I have cascade="all" in parent table's hbm.xml file. When I try to save both through my junit test case, both parent and child records get saved but when same thing is done through application running in jboss, record in parent table only gets saved.

I see this in log table, FreeTextAnswer is my child table....

2010-08-19 16:44:32,197 DEBUG [org.hibernate.engine.Cascades] cascading to saveOrUpdate: com.domain.FreeTextAnswer
2010-08-19 16:44:32,197 DEBUG [org.hibernate.engine.Cascades] id unsaved-value: 0

I tried to save unsaved-value="any" and it doesn't work.

Any idea why record in child table is not getting persisted? from log it looks like it is trying to persist record in child table.

I am using same DB scema for both test and dev/prod

Here is my DDL for parent table

Create table DTFAnswers(
DTFAnswerID int NOT NULL IDENTITY,
DTFQuestionID int NOT NULL,
StudyNumId int NOT NULL,
ModalityID int, 
PRIMARY KEY(DTFAnswerID),
FOREIGN KEY(DTFQuestionID) REFERENCES DTFQuestions (DTFQuestionID),
FOREIGN KEY(StudyNumId) REFERENCES StudyIdentification(StudyNumId),
FOREIGN KEY(ModalityID)REFERENCES Modalities(ModalityID),

Here is hbm.xml for parent table

<class name="com.domain.Dtfanswers" table="DTFAnswers" schema="dbo" catalog="IDC">
        <id name="dtfanswerId" type="int">
            <column name="DTFAnswerID" />
            <generator class="native" />
        </id>
 <one-to-one name="dtfselectedSingleAnswerChoice" class="com.domain.DtfselectedSingleAnswerChoice" cascade="all" lazy="false"></one-to-one>
        <set name="dtfselectedAnswerChoiceses" inverse="true" lazy="false" table="DTFSelectedAnswerChoices" fetch="select" cascade="all" >
            <key>
                <column name="DTFAnswerID" not-null="true" />
            </key>
            <one-to-many class="com.domain.DtfselectedAnswerChoices" />
        </set>
        <one-to-one name="dtfdateAnswer" class="com.domain.DtfdateAnswer" cascade="all" lazy="false" ></one-to-one>
        <one-to-one name="dtfbooleanAnswer" class="com.domain.DtfbooleanAnswer" cascade="all" lazy="false"></one-to-one>
        <one-to-one name="dtfnumericAnswer" class="com.domain.DtfnumericAnswer" cascade="all" lazy="false"></one-to-one>
        <one-to-one name="dtffreeTextAnswer" class="com.domain.DtffreeTextAnswer" cascade="all" lazy="false" ></one-to-one>
    </class>
</hibernate-mapping>

Below is DDL for child table

Create table DTFFreeTextAnswer(
DTFAnswerID int NOT NULL,
Value varchar(256) NOT NULL,
PRIMARY KEY(DTFAnswerID),
FOREIGN KEY(DTFAnswerID) REFERENCES DTFAnswers(DTFAnswerID),
);

Below is hbm.xml for child table

<hibernate-mapping>
    <class name="com.domain.DtffreeTextAnswer" table="DTFFreeTextAnswer" schema="dbo" catalog="IDC">
         <id name="dtfanswerId" type="int">
            <column name="DTFAnswerID" />
            <generator class="foreign">
                <param name="property">dtfanswers</param>
            </generator>
        </id>
        <one-to-one name="dtfanswers" class="com.domain.Dtfanswers" constrained="true"></one-to-one>
        <property name="value" type="string">
            <column name="Value" length="256" not-null="true" />
        </property>
    </class>
</hibernate-mapping>