-->
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: Updates object when calling Save()
PostPosted: Sat Nov 19, 2005 3:07 pm 
Newbie

Joined: Sat Nov 19, 2005 2:56 pm
Posts: 1
I have a table, Book, with an assigned primary key, BookId:

Code:
<id name="BookId" column="bookId" type="Int32" unsaved-value="0">
<generator class="assigned"/>
</id>


When saving a new Book (not updating), I want to get a primary key violation error if a book exists with the same Id. Now, even when i explicitly call session.Save(book), NHibernate updates the row... Why does this happen, and why is there Update()/SaveOrUpdate()-methods if Save() does this anyway..

Using NHibernate 1.0.1, SQL Server 2005 Express, Visual Studio 2005, C#, .NET 2.0


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 12:55 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
unsaved-value="0" means that:
if (identifier==0) Save();
else Update();
(note that even if you remove it, the default unsaved-value of integers is "0").

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 6:37 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Quote:
Now, even when i explicitly call session.Save(book), NHibernate updates the row...


This looks pretty much impossible. Can you check this once again and post more information? A small reproducible example and debug log output.


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.