@Name("blog")
@Scope(ScopeType.STATELESS)
public class BlogService
{
@In
private EntityManager entityManager;
@Unwrap
public Blog getBlog()
{
return (Blog) entityManager.createQuery("from Blog b left join fetch b.blogEntries")
.setHint("org.hibernate.cacheable", true)
.getSingleResult();
}
}
-
This component uses a
seam-managed persistence context
. Unlike the other examples we've seen, this persistence context is managed by Seam, instead of by the EJB3 container. The persistence context spans the entire web request, allowing us to avoid any exceptions that occur when accessing unfetched associations in the view.
-
The @Unwrap
annotation tells Seam to provide the return value of the method—the Blog
—instead of the actual BlogService
component to clients. This is the Seam
manager component pattern
.