I have a case where Student can be in multiple Courses, therefore I have defined this in my entity class:
@ManyToMany
@JoinTable(name = "users_courses", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "course_id", referencedColumnName = "id"))
private Collection<Course> courses;
The idea is that each user has a list of checkboxes for all courses that the user can simply check and save.
Therefore I created a CheckboxGroup that will handle this like this.
@UIScope
@SpringComponent
public class CourseSelect extends CheckBoxGroup<Course> {
private static final long serialVersionUID = 1235233604041225813L;
@Autowired
CourseRepository courseRepository;
public CourseSelect() {
setCaption("Courses");
}
@PostConstruct
private void init() {
setItems(courseRepository.findAll());
}
}
The trouble is when I run this code. I have a binder that binds complete form:
binder.bindInstanceFields(getViewComponent());
But when I run the code, I get the following error:
Caused by: java.lang.IllegalStateException: Property type ‘java.util.Collection’ doesn’t match the field type ‘java.util.Set’. Binding should be configured manually using converter.
How would I go about selecting and saving proper courses?