JPA: How to express a unique constraint including an @ElementCollection column?

后端 未结 1 1253
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 23:39

This is my JPA entity class:

@Cacheable
@Entity
public class JpaItemSearchRequest implements ItemSearchRequest {

    @Id
    @GeneratedValue
    private lon         


        
相关标签:
1条回答
  • 2021-01-03 00:00

    Unique constraint over columns in collection table can be defined by using @CollectionTable with element collection.

    @CollectionTable(
        uniqueConstraints= @UniqueConstraint(columnNames={"col1","col2"})
    )
    

    As said, those are columns of table where element collection is mapped. There is no way to have unique constraint over columns in multiple tables.

    0 讨论(0)
提交回复
热议问题