Persistence Context Collision explanation in chapter 6
posted 4 months ago
In chapter 6 of JPA Pro2, it talks about persistence context collision.
When a stateless bean in transaction scoped persistence context (PC 1 ) is running, it cannot invoke a stateful bean's extended scoped PC 2.
PC2 is eager , which means it is created when the stateful bean is initialized.
PC1 is lazy, which means it is created when the stateless bean runs its method.
Error message :javax.ejb.EJBException: There is an active transactional persistence context for the same EntityManagerFactory as the current stateful session bean's extended persistence context
PC1 cannot run inside PC2 as PC2 has been created first.
But we can do it the other way round as demo in extendedPersistenceContext example.
A stateful bean in extended scope PC 2 can invoke a stateless bean in transaction scope PC 1.
PC1 can be run inside PC2 in this case.