我只需要帮助我创建这个简单的类,其中Category包含Categories. 当我尝试使用父类别保存子类别列表时,它显示以下错误。杰森:-{ "name": "n11111111", "detail": "detail", "status" : "AVAILABLE", "subCategories": [3, 12, 100, 7, 11] // id of sub-cat}班级:-@Entity@Table(name = "category")public class Category{ @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(nullable = false, updatable = false, name = "category_id") private Long id; @Column(name = "name", nullable=false) private String name; @Column(name = "detail", nullable=false) private String detail; @Column(nullable = false, name = "status") @Enumerated(EnumType.ORDINAL) private Status status; @OneToMany( targetEntity=Category.class, cascade=CascadeType.ALL) private List<Category> subCategories;}错误:- "message": "could not execute statement; SQL [n/a]; constraint [UK_76grwe00i7mrj7awuvhc3kx0n]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement",MYSQL 错误:- #1062 - Duplicate entry代码:- 从 Vo 转换为 POJOprivate Categorie getCatToPojo(CategorieVo categorieVo, String type) { double startTime = System.nanoTime(); logger.info("Start Vo To Pojo Categorie"); // #:- case:-1 when no sub-cat there it save only below 3 attribute this.categorie = new Categorie(); this.saveNameCat(categorieVo, type); this.categorie.setDetail(categorieVo.getDetail()); this.categorie.setStatus(categorieVo.getStatus()); // #:- case:-2 when have list of sub-cat then will exe then next process }}
添加回答
举报
0/150
提交
取消