• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can I check duplicate record value in hibernate

 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Hi I am new to hibernate and struts2 and I have created the project whiich contains user registration page , in which the fields are firstnaem,middlename,lastname and emailid.Now in this I have to check that
emailid should be unique for each user so no duplicates can be provided.
Can anyone tell how can I check this through database in hibernate .
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am also a novice in database, but I guess you can try to fetch data for the given
email-id by writing a HSQL query....if no data is fetched then it means id is unique.

Manish
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Sarita,

I agree with Manish, If you are trying validate that email id entered by new user does not already exist in database, you shall have to make a DB call. You can fire the query to get the number of rows in the table having same email id, as passed by the new user, if the result is zero the email id has not already been used.

You can use various ways like Criteria, HQL, Detached Criteria, named query or native query to implement the query.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic