-->
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.  [ 6 posts ] 
Author Message
 Post subject: Update an assigned primary key
PostPosted: Tue Aug 03, 2004 12:50 pm 
Newbie

Joined: Sun Jul 25, 2004 2:13 pm
Posts: 3
I am lost going throuh the forum, hence please forgive if this question is a repeat.

I have table Foo whose identifier is an assigned value.
If there is a row in the table Foo like
5,'test' and I want to change it to
8,'test'

Can I update the identifier value?

Example:

session = HibernateUtil.currentSession();

Foo foo = (Foo) session.load(Foo.class,new Integer(5));

foo.setIdentifier(8);

session.flush();

HibernateUtil.closeSession();

If this is not supported are there any alternatives :-(

Please help !!!!!

Thanks in advance!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 12:51 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Primary keys don't change.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 12:54 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
workout I think is to delete the old one, and enter a new one.

I have never felt the need for this thought, when I have a primary key.

Why can't you just change the value of the foreign key?

Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 1:25 pm 
Newbie

Joined: Sun Jul 25, 2004 2:13 pm
Posts: 3
Thanks for reply...
subpaul wrote:
workout I think is to delete the old one, and enter a new one.


Foo is master table and there are "n" tables referring to Foo...
Hence delete and inserting would not work in my case...

subpaul wrote:
I have never felt the need for this thought, when I have a primary key.


If a user enters a wrong value for the identifier, as this identifier is assigned, user cannot be forced to delete the same and enter all the values again....

subpaul wrote:
Why can't you just change the value of the foreign key?


Is there a way out by using native sql queries for a work around


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 1:27 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Why do you use natural keys instead of a surrogate key? If this is not a legacy database application, use surrogate keys.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 2:01 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
Quote:
If a user enters a wrong value for the identifier, as this identifier is assigned, user cannot be forced to delete the same and enter all the values again....


you let the user enter their own identifier?

thats pretty weird to me.... I might be a new kid on the block, well not that new, but never seen that happen

I have always thought letting a user change the identifier is a BIG NO NO..

Quote:
Foo is master table and there are "n" tables referring to Foo...
Hence delete and inserting would not work in my case...


changing the identifier is like deleting and inserting..


but chapter 13 (wow), might be able to help you with your native queries.
http://www.hibernate.org/hib_docs/refer ... rysql.html


Pritpal Dhaliwal


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