Let’s say I’m in a loop creating JPA queries:
for(A elem : collection) {
emanager.createQuery("update A a set a.x=:y where a.id=:id")
.setParameter("id",elem.id)
.setParameter(":y", 123)
.executeUpdate();
}
Can I reuse the returned Query instance?
Query query = emanager.createQuery("update A a set a.x=:y where a.id=:id");
for(A elem : collection) {
query
.setParameter("id",elem.id)
.setParameter(":y", 123)
.executeUpdate();
}
Does it apply for all instances of Query? NamedQuery, NativeQuery, etc
Of course, I’m talking about reusing an instance within the same EntityManager, ie, within the same transaction
It is reusable for Query. As far as I’ve tried working.