-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem persisting child object - Hibernate3.0.5 and MySql
PostPosted: Fri Mar 31, 2006 12:07 am 
Newbie

Joined: Tue Jan 11, 2005 2:26 pm
Posts: 15
Hi,

I was having a problem persisting a new child object using Hibernate 3.0.5 and MySql.

I have two object TrainingTask and TrainingTaskRevision. A TrainingTask has many revisions.

TrainingTask had a set of revisions and the revision had a one-many relationship back to the task.

I mapped the TrainingTask with the inverse="true" attribute.

The mappings were fine because I could retrieve the objects. I just couldn't persist a new one by just saving the parent (TrainingTask).

My code was as follows:

// create the revision
TrainingTaskRevision revision = new TrainingTaskRevision();
// populate it's properties

// set the relationships
revision.setTask(task);
task.getRevisions().add(revision);

taskDao.save(task);

That didn't work.

All I had to do to fix this issue was add:

taskDao.save(revision);
taskDao.save(task);

***NOTE: This is a legacy database without any foreign keys between the two tables.

Real question: Does hibernate need/use the foreign keys in order to persist a child?

Here are my mapping tags:

** NOTE above classes were shortened.

<!-- Mapping inside Task object -->
<set name="taskRevisions" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="task_id" />
<one-to-many class="com.qslabs.skills.impl.TrainingTaskRevisionDb" />
</set>


<!-- mapping inside TaskRevision object -->
<many-to-one
name="trainingTask"
column="task_id"
not-null="true"
lazy="true"
class="com.qslabs.skills.impl.TrainingTaskDb" />


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

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.