user2362716
user2362716

Reputation:

Hibernate duplicate entry

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.

Upvotes: 1

Views: 1464

Answers (2)

Deepu--Java
Deepu--Java

Reputation: 3820

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

at column level.

Upvotes: 1

Adam Arold
Adam Arold

Reputation: 30528

You should create an unique constraint on the username.

@Entity
@Table(uniqueConstraints=
           @UniqueConstraint(columnNames = {"username"})) 
public class Registration {
    //...
}

Upvotes: 1

Related Questions