Suppose I am having 'subject' table
CREATE TABLE subject (id int PRIMARY KEY, name VARCHAR(255) **UNIQUE**)
and associated Mapped Object,
@Entity
@Table(name="subject")
public class SubjectDO {
@Id
@Column(name="id")
int id;
@Column(name="name", unique=true)
String name;
...
// Getter-Setter methods
}
When I try to save object having duplicate 'name' with and without 'unique=true' defined, I am getting similar behavior (same exception.) And it is obvious that JPA implementation can't really do anything unless reaching out to DB for checking.
What is the real use case for it?
(I am assuming here, unique constraint is defined at Database level too.)