-->
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: Updating primary key column(s) using Hibernate
PostPosted: Thu Sep 30, 2004 9:44 am 
Beginner
Beginner

Joined: Thu Sep 30, 2004 4:17 am
Posts: 21
Hibernate version: 2.1.4

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Informix Dynamic Server 7.24

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Some of our legacy database tables have primary keys which have some business meaning. And the application should be able to modify these keys. Hibernate doesn't allow modifying the primary keys. When I do that, I get key column value modified exception. Is there a way to handle this? Changing the table structure is not an option for me, since my application has to co-exist with the legacy application.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 11:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it's not possible, do it in a DAO method implemented using jdbc
but be carefull with first and second level caches

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 1:12 pm 
Beginner
Beginner

Joined: Thu Sep 30, 2004 4:17 am
Posts: 21
Just another thought, though not a portable solution. If I define the rowid column as a primary key instead of the actual primary key of the column, can I update the keys?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 1:46 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
read all about identities and key definition in hibernate in action, be sure to understand all this.
This is the most important part of the mapped object.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 6:58 am 
Beginner
Beginner

Joined: Thu Sep 30, 2004 4:17 am
Posts: 21
anthony wrote:
it's not possible, do it in a DAO method implemented using jdbc
but be carefull with first and second level caches


I am using a Stateless Session Bean in my application. And, retrieving the POJO in one EJB method and passing it on directly to the web-tier. The web-tier updates the POJO and sends it back to another EJB method, which would persist the object to database.

If I don't enable 2nd level cache for this POJO class, I guess Hibernate won't try to cache it. So, I have to only worry about the 1st level cache, which happens only at the Session level. For the Session cache, I could evict() the object after its use in the EJB. I guess this will take care of the caching issue. Am I missing anything?


Another related question:

Before I update the row using JDBC, I want to lock the row. Can I use the Hibernate's Session.load(Class, key, LockMode.UPGRADE) to lock the row and then use JDBC to update the same row in my EJB method?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 3:17 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
What about changing the DB schema to have a real surogate primary key. But maybe this isn't an option for you.

HTH
Ernst


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.