File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Foreign key table inserting duplicate on update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Foreign key table inserting duplicate on update" Watch "Foreign key table inserting duplicate on update" New topic

Foreign key table inserting duplicate on update

Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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
I agree. Here's the link:
subject: Foreign key table inserting duplicate on update
jQuery in Action, 3rd edition