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.  [ 1 post ] 
Author Message
 Post subject: SQL2005 mapping PK with newseqencialid()
PostPosted: Sun Dec 02, 2007 8:54 am 
Newbie

Joined: Tue Mar 13, 2007 10:52 am
Posts: 3
Hi guys and thanks for this magnificent product.

I have a design problem trying to use NHibernate on an existing database, which I don't figure out.

I have a SQLServer2005 database, with GUID as PK's. The problem is that for generating those keys, a default value of newsequencialid() is used.
My problem is that I cannot figure out a good way to map the existing tables with nhibernate, so I'd keep the database generated GUID.

Code:
[.........]
<id name="UserID" column="UserID" type="Guid">
     <generator class="native"/>
</id>
[.........]


If I use the class=native value for generator, NHibernate trys to get the SCOPE_IDENTITY(), which works for INT, but not for GUID.
Another solution would be to use class="assigned", and to generate a new sequencialID using WinAPI [using UuidCreateSequential], but if the DB is on a different machine, this won't work as expected.

I searched for that, and it seems SQL2005 has an OUTPUT keyword that might come in handy:

Code:
insert into Category (CategoryName)
output Inserted.idCategory
values ('Ima Person')


This returns the guid generated by newsequencialid().

Any ideeas on how [if possible] to implement the output in NHibernate?
Or other suggestions?

Thanks,
Raul


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.