I'm trying to do a multiple update using JPA. What I currently now, It's that is possibly to update multiple columns records in a same entity using JPA. I'm trying to avoid using update statements in loop but I couldn't find any information about this.
I'm using an entity manager
in order to execute the queries
@Override
public void updateAllNotes(List<Note> NOTES) {
LocalTime now = LocalTime.now(ZoneId.of("America/Mexico_City"));
String query = "UPDATE Note SET TITLE = :title, CONTENT = :content, UPDATED_AT = :updatedAt WHERE ID = :id";
/* I'm trying to avoid this */
for (Note note:NOTES) {
entityManager.createQuery(query)
.setParameter("title", note.getTitle())
.setParameter("content", note.getContent())
.setParameter("updatedAt", now)
.setParameter("id", note.getId())
.executeUpdate();
}
}