Dims
Dims

Reputation: 51039

How to declare CHECK constraint with Spring JPA?

How is it possible to know, which data annotations are supported by Spring JPA?

For example, is @Min supported?

   @Min(value = 0)
   private double calories;

Anyway, how can one declare CHECK constraint?

UPDATE

Please read about CHECK constraint. Also note, that @Min is a hyperlink.

Upvotes: 6

Views: 11660

Answers (1)

Rafael Fontoura
Rafael Fontoura

Reputation: 325

About validations executed by javax.validation API I don't know. But you can declare a constraint using @javax.persistence.Column annotation. For example, to create a check constraint to force accept only some values to a VARCHAR column you coul use the following code:

@Column(columnDefinition = "VARCHAR(60) CHECK (status IN ('ACTIVE', 'PENDING', 'INACTIVE')))
private String status;

Upvotes: 10

Related Questions