2
如何通过JPA注释引入多列约束?
我试图在JPA映射的实体上引入多键约束: public class InventoryItem { @Id private Long id; @Version private Long version; @ManyToOne @JoinColumn("productId") private Product product; @Column(nullable=false); private long serial; } 基本上(产品,序列)对应该是唯一的,但是我只找到一种说串行应该是唯一的方法。这显然不是一个好主意,因为不同的产品可能具有相同的序列号。 有没有办法通过JPA生成此约束,还是我被迫手动将其创建到DB?