话不言多,言简意赅就好。
用Springboot+Swagger+SpringDSataJPA框架在写网页投票接口的时候,多选批量保存数据入库(在此用的数据库为MySQL),报错:a different object with the same identifier value was already associated with the session 。
意思是:在一个session中不能进行多个实体对象的保存。
解决:在实体类(注解开发)id属性上加上注解@GeneratedValue(strategy=GenerationType.AUTO),意思是为一个实体类生成一个唯一主键。
完美解决问题。