Sample project attached and github clone located at: https://github.com/caspianb/HibernateRefreshTest/tree/HHH-12268
When using batch fetching (e.g. hibernate.default_batch_fetch_size=8), this can cause collections to become incorrectly detached from the session when performing a refresh with lock and cause LazyInitializationExceptions.
Note that this issue occurs when utilizing either EntityManager or Hibernate Session object.
{code} // OneToMany association Parent->Child // ManyToOne association Child->Parent Parent parent = em.find(Parent.class, parentId); em.createQuery("FROM Child").getResultList(); em.refresh(parent, LockModeType.PESSIMISTIC_WRITE);
// // There are two issues at this point // // This assertion fails Assert.assertEquals(LockModeType.PESSIMISTIC_WRITE, em.getLockMode(parent)); // This can cause a LazyInitializationException parent.getChildren().size(); {code} |
|