关于SpringDataJPA批量保存数据时报错的解决

话不言多,言简意赅就好。

用Springboot+Swagger+SpringDSataJP框架在写网页投票接口的时候,多选批量保存数据入库(在此用的数据库为MySQL),报错:a different object with the same identifier value was already associated with the session

意思是:在一个session中不能进行多个实体对象的保存

解决:在实体类(注解开发)id属性上加上注解@GeneratedValue(strategy=GenerationType.AUTO),意思是为一个实体类生成一个唯一主键。

完美解决问题。


猜你喜欢

转载自blog.csdn.net/harry5508/article/details/80855571
今日推荐