2

I'm using Spring 4.1 with Hibernate and have entities annotated with @OneToMany, @ManyToOne, etc.

For a certain case, class A "has many" of class B, and class A is not valid if it does not have at least one class B associated with it.

Is there a simple way to express this validation or should I write a custom validator?

Christopher
  • 1,635
  • 5
  • 19
  • 30
  • Look at this: http://stackoverflow.com/questions/5858113/how-to-make-a-manytoone-field-mandatory-in-jpa2 – Jonatan Cloutier Oct 04 '14 at 01:28
  • 1
    I think you should use a custom validator: the problem is that you said "For a certain case". You cannot define conditions into a JoinColumn annotation, nor you can define it in a jsr 303 Size validation annotation. You can also create a custom annotation: http://stackoverflow.com/questions/9284450/jsr-303-validation-if-one-field-equals-something-then-these-other-fields-sho – gipinani Oct 04 '14 at 13:15

0 Answers0