-->
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: Identity assigned after error inserting object.
PostPosted: Sun Sep 25, 2005 5:35 pm 
Hi,

I have a class defined with a UniqueIdentifier ID in SQL Server. I am using the Guid generator in my mapping file. The default value is {000...

This is a web application where NHibernate sessions are opened and closed per round trip. I am storing the object being inserted/modified in a Session variable (so it retains its attributes on round trips)

There is another attribute of this class which I have defined as a unique index in the database.

If I attempt to insert a new object into the database using SaveOrUpdate and an error occurs due to an index violation, a new identity of the object is assigned by NHibernate anyways.

This becomes problematic, because after the identity is assigned, the user is notified and can change the unique attribute to a different value, but upon trying to resave, NHibernate tries to perform an update operation as opposed to an insert operation. This is because the ID has been set and NHibernate thinks that the object is already in the database.

Is there any way around this aside from clearing the falsely assigned ID in my object?


Top
  
 
 Post subject:
PostPosted: Sun Sep 25, 2005 6:35 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate does not currently roll back identifiers. I'll add it as a feature request to JIRA, but it will probably be done only after 1.0 is released.


Top
 Profile  
 
 Post subject: Rollback transactions, sessions and modified objects
PostPosted: Fri Sep 30, 2005 4:35 am 
This is something I talked about in the issue tracking (see NH-260). I posted a comment where I asked for advice and comments about a solution for this. Meanwhile I did it and it seems to work fine (for my needs at least). If it is interesting for other people I can post the code. And of course, as I said, comments are welcome.


Top
  
 
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.