williamsandonz
williamsandonz

Reputation: 16430

Hibernate conditional @Valid

Hey guys I have an Event class with a Person object (many to one) I'm using @valid on private Person; so that it validates the person object, problem is I only want it to validate it if another property is set to 1. I.E

@Column
@Valid(if(hasAttachedPerson=1))
private Person;

Is this possible?

Upvotes: 0

Views: 691

Answers (1)

Lion
Lion

Reputation: 19037

I haven't yet used it but you may use @ValidationConditionOnUEL which defines a validation condition based on a Unified Expression Language (UEL) expression. This is very useful for checks on properties located anywhere within the bean, multiple properties, or even sub-properties.

@Valid
//defines a validation condition true if hasAttachedPerson==1
@ValidationConditionOnUEL(name = "someName", uel = "hasAttachedPerson==1")
private Person;

More details available at the "Validation condition on expression" section.

Upvotes: 1

Related Questions