mysql - 用二元运算符 mysql 查询更新列的 JPQL jpa (@Query) 是什么?
问题描述
SQL查询:
update de_meta set service_lines = service_lines | 5 where de_id = 20;
这在 SQL 控制台上运行良好。
JPA 查询:
@Modifying
@Query("update DeMetaEntity set serviceLines = serviceLines | ?2 where deId = ?1")
void addDeServiceLineMap(Integer deId, int serviceLine);
此 JPA 查询引发错误,因为 | (按位或)在 JPQL 中无效。有没有办法为给定的 SQL 查询编写等效的 JPQL?
我不想使用标准查询。当我在 JAVA INTERFACE 使用它时。
解决方案
按照 Alan 的建议创建本机查询:
@Modifying
@Query("update de_meta set service_lines = service_lines | ?2 where de_id = ?1", nativeQuery=true)
void addDeServiceLineMap(Integer deId, int serviceLine);
开关 nativeQuery=true 将按原样执行 SQL 查询。
推荐阅读
- mysql - 如何将外部模型添加到 ObjectionJS?
- python - 尝试使用 pip 安装桌面库时如何修复“错误:命令错误,退出状态 1:”?
- c - 为什么斐波那契数列的索引需要小于或等于 1?
- node.js - 如果用户有权限如何发送消息
- php - Laravel Model 有很多不同类型的模型(模型的集合)
- vuejs3 - 将数据传递给 createApp (vue)
- android - Android:如何停止 Firestore 交易?
- r - 如何合并两个数据框并仅保留不同的列(内容)?
- python - 如何跳过操作系统错误以使我的 for 循环不会中断?
- postgresql - 通过 docker 守护进程传递 sql 备份文件以填充 docker 数据库