4

Consider the following

@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;

}

Problem is I do not know how I can name the checkConstraint ? What I want is something like @Check(constraints = @Constraint("name"="CHK_CONST_1", "A IS NOT NULL OR B IS NOT NULL"))

1 Answers1

-1

I think you should used @Column and name attribute to specify the name of columns.

@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;

}

check this :- Hibernate Check Annotation

Supun Kavinda
  • 308
  • 1
  • 6
  • 20