-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one (update for parent and save for foreign)
PostPosted: Thu May 18, 2006 3:55 am 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
Hi all,
in a simple one to one mapping relation I've 2 tables "Property" and "PropertyMeasureUnit", a newly saved instance of PropertyMeasureUnit must have the same id as Property.
Everything works fine if I create in the same session both objects, but if I try to create a new instance of PropertyMeasureUnit associating it with an existing, but with no PropertyMeasureUnit already associated, instance of Property, hibernate creates a new Property, having the same properties of the one I'm trying to associate, and a new PropertyMeasureUnit.


[b]Hibernate version:[/b]
1.0.2

[b]Mapping documents:[/b]
<class name="Property" table="Property">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="hilo">
<param name="table">NH_Key_Domain</param>
<param name="column">Property</param>
<param name="max_lo">0</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<one-to-one name="PropertyMeasureUnit" class="PropertyMeasureUnit" cascade="none" />
</class>
</hibernate-mapping>

</class>
<class name="PropertyMeasureUnit" table="PropertyMeasureUnit">
<id name="Id" type="Int32" column="Id" access="field.pascalcase-m-underscore">
<generator class="foreign">
<param name="property">Property</param>
</generator>
</id>
<version name="RowVersion" column="RowVersion" type="Int32" unsaved-value="negative" />
<one-to-one name="Property" class="Property" cascade="all" constrained="true"/>
</class>
</hibernate-mapping>


[b]Code between sessionFactory.openSession() and session.close():[/b]

session.SaveOrUpdate(Property);

[b]Name and version of the database you are using:[/b]
SQL SERVER 2000


Top
 Profile  
 
 Post subject: Re: one-to-one (update for parent and save for foreign)
PostPosted: Sun May 21, 2006 6:10 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
caldarola wrote:
Everything works fine if I create in the same session both objects, but if I try to create a new instance of PropertyMeasureUnit associating it with an existing, but with no PropertyMeasureUnit already associated, instance of Property, hibernate creates a new Property, having the same properties of the one I'm trying to associate, and a new PropertyMeasureUnit.



post the code that does that, also the class declaration of your two objects.

Cheers,
Radu


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

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.