Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC ManyToMany in MultipleSelect
    text
    copied!<p>I came across to problem with ManyToMany relations between Restaurant and Tag class. I got:</p> <pre><code>public class Tag { @Id private int id; private String name; @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="tag_id")}, inverseJoinColumns={@JoinColumn(name="restaurant_id")}) private List&lt;Restaurant&gt; restaurants; </code></pre> <p>and:</p> <pre><code>public class Restaurant { @Id @GeneratedValue private int id; (...) @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="restaurant_id")}, inverseJoinColumns={@JoinColumn(name="tag_id")}) private List&lt;Tag&gt; tags; </code></pre> <p>In my jsp I got:</p> <pre><code>&lt;form:select multiple="true" path="tags"&gt; &lt;form:options items="${tagList }" itemValue="id" itemLabel="name" /&gt; &lt;/form:select&gt; </code></pre> <p>In my controller I got:</p> <pre><code>public ModelAndView myrestaurantadd(HttpServletRequest request, HttpServletResponse response, Restaurant restaurant) throws Exception { restaurantDAO.saveRestaurant(restaurant); } </code></pre> <p>When I click save button, I got error:</p> <p>Field error in object 'command' on field 'tags': rejected value [[Ljava.lang.String;@5babd8cb]; codes [typeMismatch.command.tags,typeMismatch.tags,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [command.tags,tags]; arguments []; default message [tags]]; default message [Failed to convert property value of type [java.lang.String[]] to required type [java.util.List] for property 'tags'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [beans.Tag] for property 'tags[0]': no matching editors or conversion strategy found]] with root cause org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload