-->
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: unidirectional 1:1 relationsship?
PostPosted: Thu Apr 29, 2004 7:06 am 
Newbie

Joined: Thu Apr 29, 2004 6:59 am
Posts: 1
Hello,

I have the following question:

I have a unidirectional assoziation from firma to adress. It is a 1:1 relationship:

company-mapping-file:

<hibernate-mapping>
<class name="de.bibis.eway.model.person.Firma" table="firma">
<id name="id" column="id" unsaved-value="any">
<generator class="assigned" />
</id>
<property name="name"/>
<property name="deleted" />

<one-to-one name="adresse" class="de.bibis.eway.model.person.Adresse"
constrained="true" cascade="all" />
</class>
</hibernate-mapping>



adress-mapping:

<hibernate-mapping>
<class name="de.bibis.eway.model.person.Adresse" table="adresse">
<id name="id" column="adressId" unsaved-value="any">
<generator class="native"/>
</id>
<property name="strasse"/>
<property name="plz"/>
<property name="ort"/>
<property name="deleted"/>
</class>
</hibernate-mapping>

my javaCode to insert the objects:

Firma firma = new Firma();
firma.setName("Technology");
Adresse adresse = new Adresse();
adresse.setStrasse("KKKLK");
adresse.setPlz(50896);
adresse.setOrt("Hannover");
firma.setAdresse(adresse);
firmaDAO.insert(firma);

Both object are inserted in their tables but the adress-table has no foreign-key from firma. How can it be automatically generated?

thx
Marc


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 9:41 am 
Newbie

Joined: Tue Jan 27, 2004 3:26 pm
Posts: 18
Since you didn't include your db schema i'm not sure what you exactly want to do. If you want one-to-one association with the same primary keys in both tables, You have to use generator class "foreign". If you want make this relation by introducing foreign key in address (you mentioned foreign keys) you have to us one-to-many mapping. Just read the doco:
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-onetoone
and comments for this kind of mapping.

regards,
Artur.[/url][/quote]


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.