-->
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, when to use it?
PostPosted: Wed Aug 18, 2004 11:12 am 
Newbie

Joined: Wed Aug 18, 2004 10:44 am
Posts: 14
Im new at this, and not sure if to use the one-to-one mapping. I have an object of type "dokument" which has a "destinationer". when i create a "dokument" object, it has a "destinationer" as a property. The generated classes looks fine, just like i want them to be.

But when i do
session.save()

Only the "dokument" is saved, I belived the "destinationer" would be saved as well?

Hibernate version: 2.1.6

Mapping documents:
<hibernate-mapping>

<class name="com.hypergenic.kvis.remote.generated.model.Dokument" table="dokument">
<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

<property name="navn" type="string" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<column name="navn" not-null="true" unique="true" index="dokument_navn" />
</property>

<property name="lastModified" type="long" not-null="true">
<meta attribute="use-in-tostring">true</meta>
</property>

<one-to-one name="destinationer" class="com.hypergenic.kvis.remote.generated.model.Destinationer">
<meta attribute="use-in-tostring">true</meta>
</one-to-one>

</class>

</hibernate-mapping>

<hibernate-mapping>

<class name="com.hypergenic.kvis.remote.generated.model.Destinationer" table="destinationer">

<id name="id" type="int" column="id">
<meta attribute="scope-set">protected</meta>
<generator class="foreign">
<param name="property">dokument</param>
</generator>
</id>

<property name="visMenu" type="boolean" not-null="true">
<meta attribute="use-in-tostring">true</meta>
</property>

... a lot of other properties

<one-to-one name="dokument" class="com.hypergenic.kvis.remote.generated.model.Dokument" constrained="true" />
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Transaction tx= session.beginTransaction();
session.save(dokument);
tx.commit();

Name and version of the database you are using:
MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 10:49 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
- get Hibernate in Action and read chapter 6.3
- make sure you are useing an appropriate value for the cascade attribute

HTH
Ernst


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.