-->
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: New object with pre-generated GUID
PostPosted: Mon Aug 15, 2005 11:56 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
Hey guys,

I have a tricky question. I have an object that uses a GUID as unique identifier. I know about the unsaved-value attribute in the mapping file.

In my application, the GUID is already set because it comes from an external system. Therefore, NHibernate does not know that this is a new object. Only my application or the domain object can know that (e.g. with a flag).

I'm wondering how I can tell NHibernate on the first SaveOrUpdate call to save the object rather than update it.

Thanks, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 4:09 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, you can call either Save or Update yourself, without relying on SaveOrUpdate. Another possibility is to use a version field, new objects would have it set to 0 or some other default, and existing objects will have a different value.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 5:22 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
Found the problem :-)

I used "guid" instead of "generated" for the generator algorithm.

Thanks, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 5:27 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
Personally, I'd like to see NHibernate have some interface (IAssignedIdentifier???) with a "bool IsNew" property.

ISession.SaveOrUpdate() would check to see if the object it is saving is an IAssignedIdentifier (bad name, I know) and if so, check IsNew.

This would let you override the UnsavedValue behavior for assigned IDs and other situations where it might come up instead of having to manually choose between Save or Update in your code.


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.