This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic