There's more...

Another important piece of code is the following:

@Statefulpublic 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.

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.