Siddharth Chandra Siddharth Chandra - 3 months ago 13
MySQL Question

Prevent duplicate entries in column using hibernate

I am trying to make a login system for my app using web-service,hibernate and MySql.What I am trying to do is to make separate column for phone number and email id provided by the user.I want my system to work with both the options available,I mean my login system should work for email id and as well as phone no.If my user wants to login with phone number or email id,in both way it should work.But I don't know how to make both of them unique to prevent duplicate entries.If I am using primary key it is working only with one column.I want both of them to be unique for each user registration.

Answer

If I understood what you are asking I think you can annotate the both attributes with:

@Column(unique = true)

It will make your attributes unique, so you will ensure that the data won't be duplicated.

Comments