-->
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 save a object with reference a key to other object
PostPosted: Fri Mar 19, 2010 11:35 am 
Newbie

Joined: Fri Mar 19, 2010 11:10 am
Posts: 4
I have a object1 which have an other object2 who attribute, and in the base I want to save with the object1 the idkey to the other object2.

the configured hibernate object1 is:

<hibernate-mapping>
<class name="Object1" table="Object1">
<id column="name" name="name" unsaved-value="0">
<generator class="native"/>
</id>
<property column="disable" name="disable"/>
..
<property column="xxx" name="xxx"/>
<one-to-one name="Object2Id" class="Object2" foreign-key="idObject2" cascade="all"/>
</class>
</hibernate-mapping>

and the object2 is:

<hibernate-mapping>
<class name="Object2" table="Object2">
<id column="idObject2" name="idObject2" unsaved-value="0">
<generator class="native"/>
</id>
<property column="name" name="name"/>
</class>
</hibernate-mapping>


I want that when I save the object1, save the object2 too, and put in the attribute Object2Id the key to the table Object2

but, when I do that, hibernate first do, save Object1 and a update Object2 and this throws exception because the Object2 doesn`t exist yet.
I want that do a save Object2, not a update!

Who can I do this?? What is wrong?
Thanks.


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.