JPA/JPQL-批量更新 [英] JPA / JPQL - bulk update
本文介绍了JPA/JPQL-批量更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在一个表上执行批量更新. 作一个简单的例子:
I have to perform a bulk update on a table. Making a fast example :
UPDATE Book b SET b.amount = b.amount + 1 WHERE b IN ( :books )
问题是b.amount可以是或NULL值或int,如果存在NULL值,则应表现为b.amount等于1.
The problem is that b.amount can be or a NULL value or an int, and if there is a NULL value it should behave as b.amount would be equal to 1.
JPA/JPQL中是否有任何广播"或其他方法可以解决此问题,
Is there any "cast" in JPA/JPQL or any other way to work-around this problem,
先谢谢您
关于, P
推荐答案
您应该可以使用COALESCE
:
UPDATE Book b SET b.amount = COALESCE(b.amount, 1) + 1 WHERE b IN ( :books )
这篇关于JPA/JPQL-批量更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文