Is there such thing CASE expression in JPQL?

前端 未结 3 1338
迷失自我
迷失自我 2020-12-01 04:06

Let say there is a table:

TableA:Field1, Field2, Field3

and associated JPA entity class

@Entity
@Table(name=\"TableA\")
pub         


        
3条回答
  •  情书的邮戳
    2020-12-01 04:58

    There is certainly such thing in Hibernate so when you use Hibernate as your JPA provider then you can write your query as in this example:

        Query query = entityManager.createQuery("UPDATE MNPOperationPrintDocuments o SET o.fileDownloadCount = CASE WHEN o.fileDownloadCount IS NULL THEN 1 ELSE (o.fileDownloadCount + 1) END " +
                                                " WHERE o IN (:operations)");
        query.setParameter("operations", mnpOperationPrintDocumentsList);
    
        int result = query.executeUpdate();
    

提交回复
热议问题