-->
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.  [ 3 posts ] 
Author Message
 Post subject: One-To-One Mapping
PostPosted: Wed Apr 07, 2010 11:01 am 
Newbie

Joined: Wed Apr 07, 2010 10:49 am
Posts: 2
I got a one to many mapping relation, when i try to persist the objects, the record for the one -side relation
is persisted well but, the record on the many side relation is inserted with null values,
Pls suggest... Mapping file follows

Code:
[size=85]<hibernate-mapping>
   <class name="courses.hibernate.vo.Student" table="STUDENT" dynamic-update="true"> <!-- dynamic-update="true"> -->
   
      <id name="studentID" column="STUDENT_ID">
         <generator class="native" />
      </id>
      <property name="firstName" column="FIRST_NAME" type="string" update="true"/>
      <property name="lastName" column="LAST_NAME" type="string" update="true"/>
      <property name="rollNumber" column="ROLL_NUMBER" type="integer" update="true"/>
      <many-to-one name="studentAddress" class="courses.hibernate.vo.Address"
      column="STUDENT_ADDRESS" cascade="all" not-null="true"/>
      
      <set name="phoneNumbers" table="phone_number"
                     cascade="all"
                    order-by="phoneNumberID">
                     <key column="sutdentID"/>
                     <one-to-many class="courses.hibernate.vo.PhoneNumber" />
                </set>
        </class>
</hibernate-mapping>[/size]




Code:
[size=85]<hibernate-mapping>
   <class name="courses.hibernate.vo.PhoneNumber" table="PHONE_NUMBER" dynamic-update="true"> <!-- dynamic-update="true"> -->
   
      <id name="phoneNumberID" column="PHONE_NUMBER_ID">
         <generator class="native" />
      </id>
      
      <property name="npa" column="NPA" type="string" update="true"/>
      <property name="nxx" column="NXX" type="string" update="true"/>
      <property name="line" column="LINE" type="string" update="true"/>
      <property name="phoneType" column="PHONE_TYPE" type="string" update="true"/>
      <one-to-one name="student" class="courses.hibernate.vo.Student"></one-to-one>
      
   </class>
</hibernate-mapping>[/size]


Data in Phone_Number Table follows
Phone_NO:NPA:NXX:LINE:PHONE_TYPE:STUDENT_ID
4587520;<NULL>;<NULL>;<NULL>;<NULL>;4521984;
4587521;809;547;7107;MOBILE;4521984;


Top
 Profile  
 
 Post subject: Re: One-To-One Mapping
PostPosted: Thu Apr 08, 2010 3:04 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
As I understand, your intention was to map a bidirectional relation,
but in truth you mapped 2 distinct indipendend unidirectional relations.
In order to get the relation bidirectional you must specify the inverse attribute on the many side.

Furthermore there is a misspelling in your key column
Code:
<key column="sutdentID"/>


Top
 Profile  
 
 Post subject: Re: One-To-One Mapping
PostPosted: Thu Apr 08, 2010 9:24 am 
Newbie

Joined: Wed Apr 07, 2010 10:49 am
Posts: 2
Thanks a lot for your response, The problem was not with the mapping,
The problem was in my code, from my code, the value was getting overwritten.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.