I got relation many to many between Restaurant and Tag. Here are my entities:
public class Restaurant {
@Id
@GeneratedValue
private int id;
(
You will have to define a custom property editor for the tags
property of your restaurant
object on your controller.
@InitBinder
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
super.initBinder(request, binder);
binder.registerCustomEditor(List.class, "tags",new CustomCollectionEditor(List.class){
@Override
protected Object convertElement(Object element) {
Tag tag = new Tag();
if (element != null) {
Long id = Long.valueOf(element.toString());
tag.setId(id);
}
return tag;
}
});
}