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.