-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Jean-Pierre Bergamin opened SPR-6950 and commented
See the referenced forum post for complete code coverage and log output.
In short.
Having two entities and a controller:
@Entity
public class Child {
// ...
}
@Entity
public class Parent {
@ManyToMany(cascade = CascadeType.ALL)
public Set<Child> children = new HashSet<Child>();
// ...
}
@RequestMapping(method = RequestMethod.PUT)
public String update(@Valid Parent parent, BindingResult result, ModelMap modelMap) {
for(Child child : parent.getChildren()) { // ! this throws
}
}
The Parent class has no static method findParent(Long id) that the IdToEntityConverter could use to convert a string to a Child entity.
So the conversion service tries its best to convert the info in the http request back into the HashSet "children", but inserts wrong elements into this collection. The result of the children collection is:
children = {
new HashSet {
"selectedId",
"otherSelectedId"
}
}
So instead of putting a Child entitiy with a given id into the set, the conversion service put another hashset with a string element into it.
This leads to very, very confusing (hibernate) exceptions when trying to persist the resulting entity again (https://forum.hibernate.org/viewtopic.php?f=1&t=1003029).
Affects: 3.0.1
Reference URL: http://forum.springsource.org/showthread.php?p=287402