-->
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: How to update the primary key value in db using hibernate
PostPosted: Thu Jun 12, 2008 7:38 am 
Newbie

Joined: Thu Jun 12, 2008 7:26 am
Posts: 1
Hi,
I am using spring+hibernate+jboss+oracle db
I am trying to change the primary key value of one column of table. I am sure that i am trying to insert the value is currently not there in the db.But I am getting this exception while trying to saveOrUpdate.


org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of com.nbs.ebb.persistence.Phase altered from 7 to 999998; nested exception is org.hibernate.HibernateException: identifier of an instance of com.nbs.ebb.persistence.Phase altered from 7 to 999998
org.hibernate.HibernateException: identifier of an instance of com.nbs.ebb.persistence.Phase altered from 7 to 999998
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:82)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:586)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:564)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:537)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:267)


any body can u help out pls....

Regards,
Ram


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 9:23 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Changing the primary key value of one column of table is definitely looked down upon!

Could you show us your code, and maybe we can approach your problem from a different angle?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 5:15 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Changing the pk is a bad idea...
I think you mean deleting the previous one and saving it as a new one...
Hibernate can't keep track of something that's not uniquely identified...

Or maybe consider re-designing your app as it sounds like it's not a real PK...
Maybe think about a surrogate PK. I generate a UUID in code and never change it ever again....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 11:03 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Deleting a previous record, and saving it again as a new record isn't too tough.

You can just load the record, evict it - which gives you the POJO with all of its information, delete it, and then re-save it. It'll go in with a new Id.

Just an idea.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.