-->
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: How to insert and get unique ID in return
PostPosted: Sat May 26, 2007 4:15 am 
Newbie

Joined: Fri Feb 09, 2007 9:10 pm
Posts: 3
Hello

can any one help me with this. when I insert a new row in the table, how do I get the primary key id from that newly inserted row ?

in MSSQL store procedure, there is a funciton like @@scope_identity() which return the id back to SqlCommand.

I wish the documentation is more helpful than this.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 12:07 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
You can always save the new ID in a hidden form field and then use the Load feature to load a just saved id. (At least, that's how I do it -- I'm sure there is a better way, but I do not know of it).
Code:
Client client = (Client)session.CreateQuery("from Client where ClientSSN = :ssn").SetParameter("ssn", txtClientSSN.Text).UniqueResult<Client>();

This is if your customer wants to search by Social. If you want the program to retreive the clientID from a just saved client, you can save the client (session.Save(client)), and Flush it for good measure (I'd love to know if I don't need to flush it at this point), and then simply save the clientid to a textbox.

Code:
Client client = session.Get<Client>(int.Parse(txtClientID.Text));


I use Hibernate for a WinForms application, and unfortunately, most of the examples I see are for ASP.NET 2.0. I know there isn't much difference, except I don't have to worry about state.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 27, 2007 9:03 pm 
Newbie

Joined: Fri Feb 09, 2007 9:10 pm
Posts: 3
Thanks for your help.


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