In JPA
, is it guaranteed that the transactional semantics (=effects from the database point of view) of the following snippets are identical?
Snippet A
EntityManager em = ...
List<Work> workList = ...
for(Work work : workList)
{
doWork(work); //may change some entities
}
em.getTransaction().commit();
Snippet B
EntityManager em = ...
List<Work> workList = ...
for(Work work : workList)
{
doWork(work); //may change some entities
em.flush();
em.clear();
}
em.getTransaction().commit();
In other words:
Can em.clear()
after em.flush(
) change transactional semantics (beside the fact the em.clear()
detaches all entities; it can be assumed that doWork()
is capable of dealing with that)?