• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in saving only child object for the already existing parent object in hibernate

 
vinayreddy podduturi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem in saving only child object for the already existing parent object in hibernate

i am having two classes called Topic(parent class) and Discussion(child class). So I am trying to save only discussion object for the corresponding existing topic object. So while saving its creating new parent object with child object instead of only saving child objects.

Below are my hibernate mapping configuration:

Topic: Parent

<class name="com.biperf.core.domain.forum.ForumTopic" table="FORUM_TOPIC">
<cache usage="nonstrict-read-write"/>
<id name="id" type="java.lang.Long" column="FORUM_TOPIC_ID">
<generator class="seqhilo">
<param name="sequence">FORUM_TOPIC_PK_SQ</param>
</generator>
</id>

<set name="discussion" table="FORUM_DISCUSSION" inverse="false"
lazy="false" fetch="select" cascade="all">
<key>
<column name="FORUM_TOPIC_ID" not-null="true" />
</key>
<one-to-many class="com.biperf.core.domain.forum.ForumDiscussion" />
</set>
</class>

Discussion: Child

<class name="com.biperf.core.domain.forum.ForumDiscussion" table="FORUM_DISCUSSION">

<id name="id" type="java.lang.Long" column="DISCUSSION_ID">
<generator class="seqhilo">
<param name="sequence">FORUM_DISCUSSION_PK_SQ</param>
</generator>
</id>

<many-to-one name="forumTopic" class="com.biperf.core.domain.forum.ForumTopic" lazy="false" insert="true" cascade="all" update="true" not-null="true" column="FORUM_TOPIC_ID" />
<property name="discussionTitle" type="java.lang.String" column="DISCUSSION_TITLE" />

</class>


And my java code:

forumTopic.setId( 10 ); (its already there in database)
forumDiscussion.setForumTopic( forumTopic );
forumDiscussion.setDiscussionid( Id );

save( forumDiscussion );

Please help me in solving this. I would like to save only child objects for already existing parent object in the database.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!