-->
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: updating fields in a composite key
PostPosted: Fri May 07, 2004 1:02 pm 
Newbie

Joined: Fri May 07, 2004 11:41 am
Posts: 2
We are using Hibernate version 2.1.2.

We have an object that has a primary key composed of 2 fields and we are using a composite id object. We need to be able to:

1. Retrieve an object
2. Allow the user to update the object, including the values of the fields that comprise the primary key.
3. Save the updated object (and composite id object)

The question I have is this:

What is the best approach to updating the object and the composite id object? The approach that we are planning to take is outlined below.

1) Change property setters for the composite key properties so that they remember their old values.
2) Process the change by:
- Creating a session
- Finding an instance of the object by its key (based on old key values)
- Updating that instance with the new key values from the composite id object
- committing

Does anyone has any suggestions for a better/cleaner way?

Thank you,
Julie


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you have a primary key which is not stable, you should better think about changing your database design, this will surely run you into troubles.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 1:34 pm 
Newbie

Joined: Fri May 07, 2004 11:41 am
Posts: 2
The primary key is not likely to change and if it does, it will not change frequently, but it is possible that it may change.


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.