Difference resulting from my original query and JPQL (JPA)

my own request (this is work):

Update XXX SET preDeck=deck, deck=deck+1 WHERE ... 

the result of your own query: deck = 1 and preDeck = 0 (this is what I want)

But this does not happen in JPQL:

 Update XXX SET preDeck=deck, deck=deck+1 WHERE ... 

Result: deck = 1 and preeck = 1 too

What's the solution?

RESPECT

+4
source share
1 answer

Interest Ask. What is the generated SQL for your JPQL query? What kind of JPA mechanism are you using?

In any case, the solution is to avoid update requests when using JPA, especially if the number of objects to update is small. Request entities, update their state, and let JPA discard the changes for you.

If a large number of objects need to be updated, you can still use your own query, not a JPQL query. Or you can use two queries: one that sets preDeck, and one that sets the deck in preDeck + 1.

+4
source

Source: https://habr.com/ru/post/1388010/


All Articles