-->
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.  [ 4 posts ] 
Author Message
 Post subject: Updating a primary key
PostPosted: Wed Jun 28, 2006 10:58 am 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:28 am
Posts: 22
Hi

I have a coposite primary key like this:

Code:
<composite-id>
   <key-property name="fieldName" column="FIELD_NAME"/>
   <key-many-to-one name="reportTable" class="ReportTable" column="REPORT_TABLES_ID"/>
</composite-id>
<property name="fieldDesc" column="FIELD_DESC"/>



But wenn i change the properties of such a Object, i can only change the value from the property "fieldDesc":

Code:
update
  REPORT_FIELDS
set
  FIELD_DESC=?,
where
  FIELD_NAME=? and REPORT_TABLES_ID=?



It sets only the property field "fieldDesc". How can I make, that it also updates the propertys from the composite-id? When I change the name as an example?

greets


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 11:56 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
From a database and object-oriented standpoint, if you need an object/entry to have different primary keys, you are making a new object/entry.

Best to delete the previous and enter a new object with the new primary keys

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 2:26 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
First, recall that composite id should be avoided when possible (i.e. no legacy to stick to).

Second, did you implement equals and hashCode ? http://www.hibernate.org/hib_docs/v3/re ... ompositeid
and
http://www.hibernate.org/hib_docs/v3/re ... ompositeid

I don't think it's related to your actual problem, but if you do not do this, you will hit other problem until soon :).

And final : I don't think ids are designed to change. If your entity id has to change, then I agree with kochcp, I think it's best to delete the old entry and add the new one.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 3:16 pm 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:28 am
Posts: 22
@batmat

Yes, I implemented equals and hashCode.

Ok, then i will first delete the object, and then save it again. This tables are a littlebit for nothing I know, but I cant change them.

Thanks.


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