How to introduce multi-column constraint with JPA annotations?
Posted
by plouh
on Stack Overflow
See other posts from Stack Overflow
or by plouh
Published on 2010-05-05T10:46:53Z
Indexed on
2010/05/05
10:48 UTC
Read the original article
Hit count: 248
I am trying to introduce a multi-key constraint on a JPA-mapped entity:
public class InventoryItem {
@Id
private Long id;
@Version
private Long version;
@ManyToOne
@JoinColumn("productId")
private Product product;
@Column(nullable=false);
private long serial;
}
Basically (product, serial) pair should be unique, but I only found a way to say that serial should be unique. This obviously isn't a good idea since different products might have same serial numbers.
Is there a way to generate this constraint via JPA or am I forced to manually create it to DB?
© Stack Overflow or respective owner