0

I have a field at my Java side:

@Column(name = "ads", length = 60, nullable = false)
protected String name;    

so it has an effect at SQL (I use PostgreSQL) side:

"ads" character varying(60) NOT NULL

However I want to add check constraint to it as like:

"ads" character varying(60) NOT NULL CHECK (ads <> '')

How can I define it at Java(hibernate) side?

2 Answers 2

3

You can add @NotEmpty annotation on your field.

    @NotEmpty
    @Column(name = "ads", length = 60, nullable = false)
    protected String name;
0
0

Using the Check annotation. Beware that according the this bug report, it only works at class level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.