-->
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.  [ 4 posts ] 
Author Message
 Post subject: Please help me in on delete cascade
PostPosted: Wed Dec 31, 2008 7:48 am 
Newbie

Joined: Wed Dec 31, 2008 7:35 am
Posts: 2
Hi all

I am new in Hibernate. I have two classes, Question(id is question_id) and ExamQuestion(which contain an object of Question and id is exam_question_id) what I have to do to attain on delete cascade.
-------------------------------------------------------------------------------------
Following is my ExamQuestion.hbm file

<?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>
<class name="com.ext.portlet.OCS.model.ExamQuestion" table="Ocs_Exam_Question">
<id name="examQuestionId" type="int" column="exam_question_id">
<generator class="increment" />
</id>
<many-to-one name="examQP" column="exam_qp_id" lazy="false"/>
<many-to-one name="question" column="question_id" lazy="false" />
<!-- <property name="examQPId" column="exam_qp_id" />-->

<!--<property name="questionId" column="question_id" />-->

</class>

</hibernate-mapping>
-------------------------------------------------------------------------------------
following is my Question.hbm file

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping>

<typedef class="com.ext.portlet.OCS.model.GenericEnumUserType"
name="questionType">
<param name="enumClassName">
com.ext.portlet.OCS.model.QuestionType
</param>
<param name="identifierMethod">getId</param>
</typedef>

<typedef class="com.ext.portlet.OCS.model.GenericEnumUserType"
name="complexity">
<param name="enumClassName">
com.ext.portlet.OCS.model.Complexity
</param>
<param name="identifierMethod">getId</param>
</typedef>
<class name="com.ext.portlet.OCS.model.Question" table="Ocs_Question" polymorphism="implicit">

<id name="questionId" column="question_id">
<generator class="increment" />
</id>

<property name="questionType" column="question_type" type="questionType" not-null="false"/>

<many-to-one name="techArea" column="tech_id" lazy="false"/>


<joined-subclass name="com.ext.portlet.OCS.model.ObjectiveQuestion" table="Ocs_Objective_Question">

<key column="question_id" />

<property name="question" column="question" />

<property name="complexity" column="complexity" type="complexity" />

<property name="marks" column="marks" />

<property name="markingHints" column="marking_hints" />

<bag name="answers" inverse="true" cascade="all">
<key column="question_id" />
<one-to-many class="com.ext.portlet.OCS.model.ObjectiveAnswer" />
</bag>

<many-to-one name="skillArea" column="skill_id" lazy="false"/>

<many-to-one name="topic" column="topic_id" lazy="false"/>

</joined-subclass>

<joined-subclass
name="com.ext.portlet.OCS.model.DebuggingQuestion"
table="Ocs_Debugging_Question">
<key column="question_id" />

<property name="description" column="description" />
<property name="programCode" not-null="true">
<column name="program_code" sql-type="LONGBLOB" />
</property>
<property name="totalMarks" column="total_marks" />
<property name="timeAllotted" column="time_allotted" />
<property name="name" column="name" />
<property name="fileName" column="filename" />
<property name="fileContentType" column="file_content_type" />
<property name="complexity" column="complexity"
type="complexity" />
<!-- <many-to-one name="bug" column="question_id" /> -->

<bag name="bugs" inverse="true">
<key column="question_id" />
<one-to-many
class="com.ext.portlet.OCS.model.DebuggingBug" />
</bag>

</joined-subclass>
<joined-subclass name="com.ext.portlet.OCS.model.ImplQuestion"
table="Ocs_Impl_Question">

<key column="question_id" />

<property name="name" column="name" />

<property name="description" not-null="true">
<column name="description" sql-type="LONGBLOB" />
</property>

<property name="programCode" not-null="true">
<column name="program_code" sql-type="LONGBLOB" />
</property>

<property name="descriptionFileName" column="description_file_name" />

<property name="programCodeFileName" column="program_file_name" />

<property name="totalMarks" column="total_marks" />

<property name="timeAllotted" column="time_allotted" />

<property name="complexity" column="complexity" type="complexity" />

<bag name="sections" inverse="true" cascade="all">
<key column="question_id" />
<one-to-many
class="com.ext.portlet.OCS.model.ImplSection" />
</bag>

</joined-subclass>
</class>

</hibernate-mapping>

please help me.

_________________
Thanks
Surendran P P


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2008 8:45 am 
Beginner
Beginner

Joined: Wed Nov 26, 2008 1:02 am
Posts: 22
hi

use this property,
<many-to-one cascade="all,delete-orphan">,hope soves your problem

regards,

dont forget to rate me if it solves,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2008 8:57 am 
Newbie

Joined: Wed Dec 31, 2008 7:35 am
Posts: 2
thanks for reply,

Where I have to place this in ExamQuestion.hbm

_________________
Thanks
Surendran P P


Top
 Profile  
 
 Post subject: Re..
PostPosted: Fri Jan 02, 2009 12:37 am 
Beginner
Beginner

Joined: Wed Nov 26, 2008 1:02 am
Posts: 22
hi,

in this line you have to add another attribute
<many-to-one name="question" column="question_id" lazy="false" /> like this

<many-to-one name="question" column="question_id" lazy="false" cascade="all,delete-orphan" />

hope it solves your problem

regards,

dont forget to rate me if it solves,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.