Reputation: 38705
So I have a entity Notification
, that has a boolean attribute readStatus
to determine of a notification has been read or not. When I click a button, I want to write a JPQL that retrieve the unread notifications (readStaus=false
) and set the readStatus
of those unread notifications to true
Note: I dont want to write jpql to retrieve the list and manually loop through the list to set the readStatus
and merge them back to the database
Upvotes: 0
Views: 493
Reputation: 38705
Here is the solution
UPDATE Notification n SET n.readStatus = true WHERE n.readStatus = false
Upvotes: 3
Reputation: 691645
List<Notification> notifications =
em.createQuery("select n from Notification n where n.readStatus = false")
.getResultList();
for (Notification n : notifications) {
n.setReadStatus(true);
}
Upvotes: 0