-->
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 relationship
PostPosted: Fri Jun 04, 2004 4:11 am 
Newbie

Joined: Fri Jun 04, 2004 3:48 am
Posts: 2
Location: Bali
Hi all,

I have two tables: MastRec and OutpRec which both extended from class PKMastRec and have one to one relationship with this mapping on OutpRec.hbm.xml:

<one-to-one name="mastRec" class="com.mitrais.kms.service.MastRec" cascade="all" outer-join="auto"/>

I want the relationship behaves like this:
Every creation and modification on table OutpRec will affect table MastRec.

I create a test case for record creation on table OutpRec, but unfortunately it did not behave properly. Every record creation on table OutpRec will UPDATE (not CREATE) record on MastRec.

The log is:

Hibernate: insert into KMS_SERV_OUTP_REC (NEW_CASE, SUBJECTIVE, OBJECTIVE, ASSES_DESC_1, ICD_CODE_1, ASSES_DESC_2, ICD_CODE_2, ASSES_DESC_3, ICD_CODE_3, PLAN, DISMISSAL_CODE, BED_REST, MR_NO, MR_DATE, MR_TYPE, MR_SEQ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Hibernate: update KMS_SERV_MAST_REC set ACTION_CODE=?, ACTV_GRP_ID=?, ACTV_ID=?, DOCTOR_ID=?, STAFF_ID=?, ICD_CODE=?, CREATED_BY=?, CREATED_DATE=?, LAST_UPD_BY=?, LAST_UPD_DATE=? where MR_NO=? and MR_DATE=? and MR_TYPE=? and MR_SEQ=?


Does anyone know how to solve this problem?


Regards,

-Made Eka-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 05, 2004 9:30 am 
Beginner
Beginner

Joined: Thu May 13, 2004 5:51 am
Posts: 28
Do you also have the one-one mapping in MastRec hbm? This will imply that the two have a primary key association. So the identifiers to both their persistent instances will be the same. This will help save, update and delete to cascade appropriately.

There are other ways to define a one-one association.. you could read that up in Chapter 5 of Hibernate reference.

--


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 10:01 pm 
Newbie

Joined: Fri Jun 04, 2004 3:48 am
Posts: 2
Location: Bali
Yes it is. Both table will have identical primary key PKMastRec so they are extended from that class. I think one to one relationship suits this, but the cascading behavour did not work properly. On adding a new record, it is INSERTED into OutpRec but UPDATED (not INSERTED) into MastRec table. I tried to set this in OutpRec.hbm.xml:

Code:
<composite-id name="comp_id" class="com.mitrais.kms.service.PKMastRec" unsaved-value="any">


but it still did not work.


Regards,

-Made Eka-


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.