Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public class Series {
  2. @Id
  3. @GeneratedValue
  4. private long id;
  5.  
  6. @ElementCollection
  7. @CollectionTable(name = "series_food")
  8. @MapKeyColumn(name = "fid")
  9. @Column(name = "num")
  10. private Map<Food, Integer> foods = new HashMap<>();
  11. }//constructors, getters and setters are ignored
  12.  
  13. @GetMapping("/series/{sid}")
  14. public String getSeries(@PathVariable("sid") Long sid, Model model) {
  15. Series series = producerService.getSeries(sid);
  16. model.addAttribute("series", series);
  17. return "rest/series";
  18. }
  19.  
  20. @PostMapping("/series")
  21. public String saveSeries(@Valid Series series, Model model) {
  22. System.out.println("calling addSeries");
  23. Series series1 = producerService.modifySeries(series);
  24. model.addAttribute("series", series1);
  25. return "rest/series";
  26. }
  27.  
  28. <tr th:each="f,ptr : *{foods}">
  29. <th ><input type="text" th:value="${f.key.name}"></th>
  30. <th><input type="text" th:value="${f.value}" th:field="*{foods[__${f.key}__]}"></th>
  31. </tr>
  32.  
  33. 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]';
  34. 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';
  35. 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';
  36. 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