| Steve Ebersole, it's not obvious (at least to me) that the following could cause concurrent access to Session/EntityManager.:
em.createQuery("from MyEntity").getResultList().parallelStream()
.forEach((e) -> {
e.getReferencedEntity();
e.getAnotherReferencedEntity();
});
It happens here because the entities are lazy and get initialized. Collection#parallelStream Javadoc says: "Returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream." I think it would be worth at least documenting that calling List#parallelStream on the List returned by Query#getResultList can cause problems if it contains lazy entities, associations, or properties. |