-->
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.  [ 2 posts ] 
Author Message
 Post subject: Updating and entity with primary key zero
PostPosted: Fri Oct 17, 2008 12:20 pm 
Newbie

Joined: Fri Oct 17, 2008 12:05 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: Hibernate3 3.2.3.ga

Mapping documents:
<id name="id" type="long" column="Id">
<generator class="increment" />
</id>

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:
DB2 version9.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problem with an entity with primary key zero
Following is the description of the problem
I have an entity whose primary key is defined as
<id name="id" type="long" column="Id">
<generator class="increment" />
</id>
in its hbm mapping file

There is a row in the corresponding table for that entity in DB2 with id zero
I want to retrieve this entity with id zero, modify it and then update it in the database.
The retrieval works perfectly fine but update creates a new entity instead of updating the entity with id zero with the modification

Can any one tell me what is wrong.

Thanks in advance

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2008 1:02 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
You are probably calling update() unnecessarily.
session.update() does not do what you think it does.
Please read this article

http://hibernar.org/articulos_en/persis ... ethods.php


where I explain this in detail

_________________
Gonzalo Díaz


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