17.5. Simplifying persistence with Seam
All the previous examples in this chapter use the EntityManager that was injected by the EJB 3.0 container. A member field in an EJB is annotated with @PersistenceContext, and the scope of the persistence context is always the transaction started and committed for a particular action method. In Hibernate terms, a Hibernate Session is opened, flushed, and closed for every method called on a session bean.
When a session bean method returns and the persistence context is closed, all entity instances you loaded from the database in that bean method are in detached state. You can render these instances on a JSF page by accessing their initialized properties and collections, but you get a LazyInitializationException ...
Get Java Persistence with Hibernate 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.