-->
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: Trigger-generated primary key from sequence
PostPosted: Fri Aug 19, 2005 5:36 am 
Newbie

Joined: Fri Aug 19, 2005 5:29 am
Posts: 1
I am trying to switch a project over to NHibernate. We use an Oracle database with primary keys automatically filled in from a sequence by a trigger. As far as I can tell, NHibernate doesn't yet support this very common construct. I have tried with a sequence generator referring to the same sequence as the trigger does, but this only results in the sequence being incremented twice, with NHibernate and the database operating with different keys.

Does anybody know a reasonable workaround? Changing the database is not an option.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 2:42 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
Looks like you'll have to do manual SQL to get an object started and won't be able to Save() the object with NHibernate.

And I disagree that this is a common strategy. It's boneheaded for a number of reasons. For instance, if you needed to copy rows from a backup table in to that table, they'd all get new primary keys due to the trigger.

I know you can't change the DB, but the trigger is completely unnecessary.

It saves a couple of characters in the SQL when you do an INSERT *and you don't care about the new primary key*. Other than that, it has absolutely zero benefits over

INSERT INTO foo (x, y, z) VALUES (my_seq.NEXTVAL, yval, zval)

You could use a CHECK constraint to make sure the new ID wasn't greater than the current value of the sequence if you were really paranoid that someone was going to insert a row with an ID that would collide with a future value of the sequence.[/i]


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.