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: how to check the id already exists in database
PostPosted: Wed Feb 07, 2007 7:24 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
I have table with 3 columns id , name , password where id is incremented automatically . During me insert operation i must check wheather the id ie already exists in the table r not . If yes i must allow him to save it to database . How i do this in hibernate


help me

bye
mano


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 7:55 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi mnrnjn

Try saveOrUpdate method

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Thanks for ur reply
PostPosted: Wed Feb 07, 2007 8:14 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:46 am
Posts: 31
Hi
Can u explain me in detail . My need is to check the available id in table
if the user enters the same id as in the table . i must not allow him to save in to database . How this can be done in hibernate....

bye
mano


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 8:21 pm 
Newbie

Joined: Wed Feb 07, 2007 6:05 pm
Posts: 10
Make the database do this.

If the id is your primary key, you cannot insert a duplicate.

The other way is to query the database using the id the user entered and if you get a data back it exists.

the SQL would be

select count(*) from TABLE where id=user-id

if you get 0 you are good to go.


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.