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.
Asked
Active
Viewed 3,342 times
1 Answers
1
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.

Ismaell Gass
- 56
- 1
- 7
-
How would I know if a user is trying to insert any duplicate entry in the database. – Siddharth Chandra Aug 25 '16 at 02:53
-
hava a look at this post http://stackoverflow.com/questions/3502279/how-to-handle-jpa-unique-constraint-violations – Ismaell Gass Aug 25 '16 at 04:48
-
My program throws an ConstraintViolationException,But how would i know which column throws that exception. – Siddharth Chandra Aug 25 '16 at 06:01
-
You don't. You need to write your own validation to check this prior to doing the insert. – Alan Hay Aug 25 '16 at 12:39