gpt4 book ai didi

HIbernate 通过 JPA 检查约束名称

转载 作者:行者123 更新时间:2023-12-05 08:07:48 27 4
gpt4 key购买 nike

考虑以下问题

@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 OR B IS NOT NULL"))

最佳答案

我认为您应该使用@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

关于HIbernate 通过 JPA 检查约束名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53234500/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com