- Java EE 8 Cookbook
- Elder Moraes
- 72字
- 2025-02-17 14:53:40
There's more...
Another important piece of code is the following:
@Stateful
public class UserBean {
@PersistenceContext(unitName = "ch02-jta-pu",
type = PersistenceContextType.EXTENDED)
private EntityManager em;
...
}
So, here we are defining our PersistenceContext as EXTENDED. It means that this persistence context is bound to the @Stateful bean until it is removed from the container.
The other option is TRANSACTION, which means the persistence context would live only by the time of transaction.