• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Foreign key table inserting duplicate on update

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i have user and user_detail table very simple with one to one mapping. the issue is its saving fine but when i update it inserts a new row only in the user_details table.
user table is of
user_id
password

user_details is of
userid references user(user_id),
user_first_name .....

here is my mapping file. the isue is any update to user tabel are fine but when i try to update the first name it insert a duplicate row in teh user_Details table. let me stress one thing here i get the user object first closes the session. then again after getting the user input i create the user object and run and do an update on that. i read in some post the same session should be used for fetching and updating which doesn't make sense since you first fetch data present to the user get his input manipulte teh object layer and run an upate on that. any help
<hibernate-mapping auto-import="true" default-lazy="false">

<class name="com.hms.model.User" table="user">
<id name="userId" column="user_id">
<generator class="assigned"/>
</id>
<property name="password">
<column name="password" />
</property>
<property name="userType">
<column name="user_type_id" />
</property>
<one-to-one name="userDetails" class="com.hms.model.UserDetails" cascade="all" constrained="true" />
</class>



<class name="com.hms.model.UserDetails" table="user_details">

<id name="userId" column="user_id">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<one-to-one name="user" class="com.hms.model.User" constrained="true" />
<property name="userFirstName">
<column name="user_first_name" />
</property>
<property name="userMiddleName">
<column name="user_middle_name" />
</property>
<property name="userLastName">
<column name="user_last_name" />
</property>
<property name="userWorkPhone">
<column name="user_work_phone" />
</property>
<property name="userHomePhone">
<column name="user_home_phone" />
</property>
<property name="userMobilePhone">
<column name="user_mobile_phone" />
</property>

<property name="userDob">
<column name="user_dob" />
</property>
<property name="userEmail">
<column name="user_email" />
</property>
</class>

</hibernate-mapping>
my java code is very simple i open the sesion and do a
session.saveOrUpdate(user)
Thanks
Rashid
 
reply
    Bookmark Topic Watch Topic
  • New Topic