JPA Composite Key + Sequence

后端 未结 4 381
春和景丽
春和景丽 2021-02-02 14:51

Is it possible in plain JPA or JPA+Hibernate extensions to declare a composite key, where an element of the composite key is a sequence?

This is my composite class:

4条回答
  •  佛祖请我去吃肉
    2021-02-02 15:02

    Try like this:

    @TableGenerator(name = "canonicalKeys", allocationSize = 1, initialValue = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "canonicalKeys")
    @Column(name = "CANONICAL_ID", unique = false, nullable = false, insertable = true, updatable = true)
    public String getCanonicalId() {
        return canonicalId;
    }
    

    In this way instead of using a sequence you can use a table.

提交回复
热议问题