-->
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: SQL Server Identity
PostPosted: Thu Sep 16, 2004 10:38 am 
Newbie

Joined: Tue Sep 14, 2004 10:57 am
Posts: 12
Geniuses,

I have a table in SQL Server whose ID field is an IDENTITY type. We have the
Code:
public boolean onSave(Session s) throws CallbackException

overriden to call a method that generates another field. But to method requires the ID value!! Is there way that I can ID value to pass to my function prior to the 'full-save'? I know that Hibernate utilizes the 'select @@IDENTITY' but thats after the save.

Thanks,

jay


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 2:00 pm 
Newbie

Joined: Tue Sep 14, 2004 10:57 am
Posts: 12
ok another problem.... SQL Server go fig... How can I get the next value of the IDENTITY field and how do I configure or implement something in Hibernate to handle this?

Thanks and regards,

Jay

(PS- I'm starting to really dislike MSSQL!!)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
identity generator is done for this for the id

if you wanna hit this for another field, write a JDBC method in a DAO layer

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 5:08 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Jay,

There's no way to find out what the next generated identity value is going to be, from a very simple reason: even if you had a way to find out, there would be a chance that someone else inserted a row between the moment you found out the value and the moment you made your insert.

If you really find Oracle sequences that convenient, you could either write a stored procedure to generate sequences based on a table with counters (lock the row, get the value, increment, unlock). You could even write a (very simple) Dialect implementation to handle sequence generation in Hibernate using your stored procedure.

On the other hand, there's no problem with the "full-save". If something occurs after you inserted the row and found out the generated id, you can always rollback the transaction. (I guess you're doing this inside a transaction, aren't you?)

Alin.


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.