'Updating multiple fields from a HQL subquery
I have two entities, CatalogItem and StockItem, and I want to update two fields in the first one with values from the second one.
Right now i am doing it this way:
UPDATE CatalogItem ci SET
ci.availableQuantity = (SELECT availableQuantity FROM StockItem si WHERE /* some conditions */),
ci.physicalQuantity = (SELECT physicalQuantity FROM StockItem si WHERE /* the same conditions */)
WHERE ci.supplier.id = :supplierId AND ci.lastFeedUpdate < :updateTimestamp
Is there a way to do the StockItem subquery just once, retrieving both fields and using them in an update?
I can do it in SQL, with a native query, but I was wondering if there was a HQL way to achieve the same behavior.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
