通过JPA的HIbernate检查约束名称

时间:2018-11-09 23:22:57

标签: hibernate jpa

请考虑以下内容

@Entity
@Table
@Check(constraints = "A IS NOT NULL OR B IS NOT NULL")    
public class Model {

@Id
private Long id;

private A a;

private B b;

}

问题是我不知道如何命名checkConstraint吗? 我想要的是类似@Check(constraints = @Constraint(“ name” =“ CHK_CONST_1”,“ A IS NOT NULL或B IS NOT NULL”))的东西

1 个答案:

答案 0 :(得分:0)

我认为您应该使用@Columnname属性来指定列的名称。

@Entity
@Table
@Check(constraints = "COL_A IS NULL OR COL_B IS NOT NULL")    
public class Model {

   @Id
   private Long id;

   @Column(name = "COL_A")
   private A a;

   @Column(name = "COL_B")
   private B b;

}

检查此:-Hibernate Check Annotation