Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Series {
- @Id
- @GeneratedValue
- private long id;
- @ElementCollection
- @CollectionTable(name = "series_food")
- @MapKeyColumn(name = "fid")
- @Column(name = "num")
- private Map<Food, Integer> foods = new HashMap<>();
- }//constructors, getters and setters are ignored
- @GetMapping("/series/{sid}")
- public String getSeries(@PathVariable("sid") Long sid, Model model) {
- Series series = producerService.getSeries(sid);
- model.addAttribute("series", series);
- return "rest/series";
- }
- @PostMapping("/series")
- public String saveSeries(@Valid Series series, Model model) {
- System.out.println("calling addSeries");
- Series series1 = producerService.modifySeries(series);
- model.addAttribute("series", series1);
- return "rest/series";
- }
- <tr th:each="f,ptr : *{foods}">
- <th ><input type="text" th:value="${f.key.name}"></th>
- <th><input type="text" th:value="${f.value}" th:field="*{foods[__${f.key}__]}"></th>
- </tr>
- Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'foods[ycqian.yummy.entity.food.Food@483408f]' of bean class [ycqian.yummy.entity.food.Series]: Invalid index in property path 'foods[ycqian.yummy.entity.food.Food@483408f]';
- nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'ycqian.yummy.entity.food.Food' for property 'null';
- nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'ycqian.yummy.entity.food.Food@483408f';
- nested exception is java.lang.NumberFormatException: For input string: "ycqian.yummy.entity.food.Food@483408f"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement