aspose file tools*
The moose likes Object Relational Mapping and the fly likes Problem in saving only child object for the already existing parent object in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem in saving only child object for the already existing parent object in hibernate" Watch "Problem in saving only child object for the already existing parent object in hibernate" New topic
Author

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

vinayreddy podduturi
Greenhorn

Joined: Mar 11, 2012
Posts: 13
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
 
subject: Problem in saving only child object for the already existing parent object in hibernate