hibernate. How to add unique index for field combination?
constraints, hibernate, java, jpa, unique
Solution
I think it will works :
@Table(name="UserPattern",
uniqueConstraints=
@UniqueConstraint(columnNames={"user_id", ""})
or
@Table(name="UserPattern", uniqueConstraints={
@UniqueConstraint(columnNames={"user_id", "patern_id"})
})
Problem
I have following hibernate mapping: ``` @Entity public class UserPattern { @Id @GeneratedValue Integer id; @ManyToOne @JoinColumn(name = "user_id") User user; @ManyToOne @JoinColumn(name = "patern_id") Pattern pattern; ... } ``` Does hibernate allow to add unique index that combination of `user` and `pattern` was unique ?