• Post Reply Bookmark Topic Watch Topic
  • New Topic

Foreign key table inserting duplicate on update  RSS feed

Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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_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"/>
<property name="password">
<column name="password" />
<property name="userType">
<column name="user_type_id" />
<one-to-one name="userDetails" class="com.hms.model.UserDetails" cascade="all" constrained="true" />

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

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

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

my java code is very simple i open the sesion and do a
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!