V
V
VeoQlewer2018-10-15 13:26:50
Hibernate
VeoQlewer, 2018-10-15 13:26:50

How to set a limit on the number of links in Hibernate?

@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
@JoinTable(name = "movies_directors",
joinColumns = @JoinColumn(name = "movie_id"),
inverseJoinColumns = @JoinColumn(name = "director_id"))
Set directors = new HashSet();
This is a description of a many-to-many relationship using annotations. A movie can have multiple directors - a director can have multiple movies. If I want each movie to have between 1 and 4 directors, how do I set this limit?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-10-15
@VeoQlewer

Add a setter to the entity class that controls the addition of elements to the field directors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question