1

I have Registration table.That has many duplicate entries. Here duplicate entries in terms of same username. so I want to know how to prevent the duplicate entries in a table. I am using Hibernate and java servlet.

1
  • make the username column unique in your schema. There is nothing to do with hibernate. And handle the unique name exception in your code. Commented Mar 10, 2014 at 12:36

2 Answers 2

1

You should create an unique constraint on the username.

@Entity
@Table(uniqueConstraints=
           @UniqueConstraint(columnNames = {"username"})) 
public class Registration {
    //...
}
Sign up to request clarification or add additional context in comments.

Comments

1
@Column(name = "username",unique=true)

at column level.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.