[英]Batch Update by different values using Spring JPA/Hibernate
There is Java entity class:有Java实体类:
class Call {
int callId,
String callStatus
}
callStatus posibly values : SETUP, INSTALLED, FINISHED callStatus 可能的值:SETUP、INSTALLED、FINISHED
And table calls_statuses has values表call_statuses有值
callId callStatus
1 SETUP
2 INSTALLED
3 INSTALLED
Then i need change statuses for callId 1 and 2 as :然后我需要将 callId 1 和 2 的状态更改为:
1 INSTALLED
2 FINISHED
The call with callId 3 left same. callId 3 的呼叫保持不变。
Is it possible to make a batch update using Spring JPA/Hibernate?是否可以使用 Spring JPA/Hibernate 进行批量更新?
Try something like this, a custom JPQL query would like:尝试这样的事情,自定义 JPQL 查询会像这样:
@Query("Update CallStatuses cs SET cs.callStatus = CASE WHEN (cs.callId IN :calls1) THEN :callStatusInstalled WHEN (cs.id IN :calls2) THEN :callStatusFinished END")
batchUpdateCallStatus(@Param("calls1")List<int> calls1,
@Param("calls2") List<int> calls2,
@Param("callStatusInstalled") String callStatusInstalled,
@Param("callStatusFinished") String callStatusFinished);
Posssible duplicate: JPQL - Update with Multiple where conditions可能重复: JPQL - 使用多个 where 条件更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.