Question

I'm wondering if there is an option in hibernate where I can configure a manytomany field to be required? Normally I would add nullable = false but it can't be added inside these annotations.

@ManyToMany(cascade = { CascadeType.ALL })
@JoinTable(name = "attribuutlabel",
        joinColumns = { @JoinColumn(name = "valueid") }, inverseJoinColumns = { @JoinColumn(name = "attribuutlabel") })
private List<Label> labels;

Is it even possible in hibernate or should I validate my users input for having associated a label when they use this relation?

Thank you very much

Was it helpful?

Solution

What version of Java EE are you using?

If it's EE 6: add a @NotNull on the labels

if it's EE 5: add @NotNull include Hibernate Validator in the classpath of your app. include bean validation (JSR 303) api in the classpath of your app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top