-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Not able to insert Children
PostPosted: Tue Dec 25, 2007 7:50 am 
Newbie

Joined: Thu Feb 22, 2007 6:42 am
Posts: 9
Hibernate version:
3.2

I am trying to insert a parent object which contains child reference .. it is inserting the parent(evaluation) but it is not inserting any child object

Evaluation <1 is parent to *> Questionnaire <1 is parent to *> psychodiagnositch_questinnaire

one evaluation object contains a collection of questionnaire and each questinnaire contains mulitple psychodiagnostich_questionnaire.


There is no problem with hibernate connectiviti issue, since i am able to insert in single table .. i am using spring for session and other thingy.

Here are the mapping documents for 3 tables


Mapping documents:

  • Evaluation
    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="com.careway.domain.hibernate">
      <class name="com.careway.domain.hibernate.EvaluationImpl" table="evaluation" optimistic-lock="none">
        <id name="id" type="integer" unsaved-value="0">
          <column name="id" not-null="true" unique="true" index="PRIMARY"/>
          <generator class="increment"/>
        </id>
        <property name="evaluationDate" type="timestamp" column="evaluation_date" not-null="true"/>
        <property name="instructions" type="string" column="instructions" length="300"/>
        <many-to-one name="evaluatedBy" entity-name="com.careway.domain.hibernate.UserImpl" cascade="none" foreign-key="evaluation_ibfk_2" column="evaluated_by"/>
        <many-to-one name="patientProfile" entity-name="com.careway.domain.hibernate.PatientProfileImpl" cascade="none" foreign-key="evaluation_ibfk_1" column="patient_profile_id"/>
        <set name="questionnaire" inverse="true" cascade="none">
          <key foreign-key="questionnaire_ibfk_1" not-null="true" column="evaluation_id"/>
          <one-to-many entity-name="com.careway.domain.hibernate.QuestionnaireImpl"/>
        </set>
      </class>
    </hibernate-mapping>

  • Questionnaire
    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="com.careway.domain.hibernate">
      <class name="com.careway.domain.hibernate.QuestionnaireImpl" table="questionnaire" optimistic-lock="none">
        <id name="id" type="integer" unsaved-value="0">
          <column name="id" not-null="true" unique="true" index="PRIMARY"/>
          <generator class="increment"/>
        </id>
        <property name="dateTime" type="timestamp" column="date_time"/>
        <many-to-one name="questionnaireType" entity-name="com.careway.domain.hibernate.QuestionnaireTypeImpl" cascade="none" foreign-key="questionnaire_ibfk_2" column="questionnaire_type_id"/>
        <many-to-one name="evaluation" entity-name="com.careway.domain.hibernate.EvaluationImpl" cascade="none" foreign-key="questionnaire_ibfk_1" column="evaluation_id"/>
        <set name="psychodiagnostichQuestionnaire" inverse="true" cascade="none">
          <key foreign-key="psychodiagnostich_questionnaire_ibfk_1" column="questionnaire_id"/>
          <one-to-many entity-name="com.careway.domain.hibernate.PsychodiagnostichQuestionnaireImpl"/>
        </set>
      </class>
    </hibernate-mapping>

  • Psycho ...
    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="com.careway.domain.hibernate">
      <class name="com.careway.domain.hibernate.PsychodiagnostichEvaluationResultImpl" table="psychodiagnostich_evaluation_result" optimistic-lock="none">
        <id name="id" type="integer" unsaved-value="0">
          <column name="id" not-null="true" unique="true" index="PRIMARY"/>
          <generator class="increment"/>
        </id>
        <property name="instructions" type="string" column="instructions" length="300"/>
        <property name="identifiedCategory" type="string" column="identified_category" length="50" not-null="true"/>
        <property name="threatLevel" type="integer" column="threat_level" not-null="true"/>
        <many-to-one name="evaluationResult" entity-name="com.careway.domain.hibernate.EvaluationResultImpl" cascade="none" foreign-key="psychodiagnostich_evaluation_result_ibfk_1" column="evaluation_result_id"/>
      </class>
    </hibernate-mapping>




Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 6:41 am 
Newbie

Joined: Thu Aug 16, 2007 3:02 am
Posts: 12
Location: Banglore
Hi,
Please put cascade="save-update" in the mapping of child objects.
It will save the child too .

_________________
sirajulmuneer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.