-->
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: [HELP] One-To-One association and Foreign Key
PostPosted: Mon Jun 01, 2009 7:30 am 
Newbie

Joined: Mon Jun 01, 2009 7:06 am
Posts: 3
Hi all,

I have a quite newbie question for you. I have my app with a simple One-To-One association and I have a problem managing the foreign key between the two associated class.

Domain objects:

Code:
public class Fonte {
   
   private int idFonte;   
   private String nome;   
   private String link;
   private NavXML xmlDescriber; //one-to-one associated object with foreign key on the DB
//getters&setters
}

public class NavXML {
   private String contentCrawling;
   private String contentWrapping;
   private int idNavXML;
   private String description;
//getters&setters
}


and here we have the mapping files:
Code:
<hibernate-mapping>
   <class name="Fonte" table="FONTI">
      <id name="idFonte" column="id_fonte"><generator class="native"/> </id>
      <property name="nome" column="nome"/>
      <property name="link" column="link"/>
      <one-to-one name="xmlDescriber" class="NavXML" cascade="all" constrained="true" />
   </class>
</hibernate-mapping>

<hibernate-mapping>
<class name="NavXML" table="XMLNAV">
      <id name="idNavXML" column="id_xml_nav"> <generator class="native"/> </id>
      <property name="contentCrawling" column="content_crawling" type="text"/>
      <property name="contentWrapping" column="content_wrapping" type="text" />
      <property name="description" />
</class>
</hibernate-mapping>


in the DB (MySQL) I have a foreign key between the table FONTI to the table XMLNAV based on the id_nav_xml .
The problem is that I can't get the same id assigned on a newly created NAVXML object and in the field of the foreign key in the FONTI table.
In other words, how can I force to have the same value in the XMLNAV table id field and in the FONTI table foreign key field?

At the moment I get a NULL value in the foreign key field of the FONTI table when I try to insert an object of type Fonte.

Thank you in advance.

Regards

PS:Sorry for my English


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.