I have a Java bean. Now, I want to be sure that the field should be unique.
I am using the following code:
@UniqueConstraint(columnNames={\"username\
Note: In Kotlin the syntax for declaring the arrays in annotations uses arrayOf(...) instead of {...}
@Entity
@Table(uniqueConstraints=arrayOf(UniqueConstraint(columnNames=arrayOf("book", "chapter_number"))))
class Chapter(@ManyToOne var book:Book,
@Column var chapterNumber:Int)
Note: As of Kotlin 1.2 its is possible to use the [...] syntax so the code become much simpler
@Entity
@Table(uniqueConstraints=[UniqueConstraint(columnNames=["book", "chapter_number"])])
class Chapter(@ManyToOne var book:Book,
@Column var chapterNumber:Int)