springdatajpa执⾏update和delete语句时报错处理
之前项⽬中使⽤spring data jpa时,遇到删除记录的需求时,主要利⽤spring data中⾃带的delete()⽅法处理,最近在dao层使⽤delete sql语句时报错,代码如下:[java]
1. @Query(value = "delete parcel,parcel_file,ms_files,t_order,route " +
2. "from parcel left join route ute_id = route.id" +
3. " left join t_order on t_order.parcel_id = parcel.id" +mandatory
4. " left join parcel_file on parcel.id = parcel_file.parcel_id" +
5. " left join ms_files on parcel_file.file_uuid = ms_files.uuid " +
cleaner6. "where parcel.id = ?1", nativeQuery = true)
7. void deleteByParcelId(Long parcelId);
报错提⽰:
最后查阅资料发现了解决办法,同时加上注解@Modifying和Transactional
[java]
1. @Modifying
德语学习培训班
2. @Transactional
alarm是什么意思
3. @Query(value = "delete parcel,parcel_file,ms_files,t_order,route " +
dominated4. "from parcel left join route ute_id = route.id" +
5. " left join t_order on t_order.parcel_id = parcel.id" +
6. " left join parcel_file on parcel.id = parcel_file.parcel_id" +
yokozuna
7. " left join ms_files on parcel_file.file_uuid = ms_files.uuid " +
between的英语怎么读啊
8. "where parcel.id = ?1", nativeQuery = true)
9. void deleteByParcelId(Long parcelId);
加上两个注解后问题成功解决了,只加上其中任意⼀个注解还是会报错,只有同时加上两个注解时才可以。
@Modifying注解与@Query⼀起使⽤表⽰将查询操作标识为修改查询,这样框架最终会⽣成⼀个更新的操作,⽽⾮查询自学网
英语语法大全下载customize是什么意思@Transactional:spring整合jpa时⽤于注释事务