I am writing a web application (Tomcat 7) so no JTA and want to display a list of projects including the tasks associated to each project in a JSF page.
There are 2 entities – Project which contains a Collection of Tasks. From my Managed Bean I call a convenience method to retrieve all the active the Projects, then iterate (ui:repeat) over this Collection of Projects and want to display the Tasks per Project. When I try t do this I get a Persistence Exception since the Persistence Context is no longer in scope.
Without creating backing beans of the Project and Task and without making use of an Extended Context what other options do I have.
Have your convenience method also fetch the tasks, for instance by joining that association in the query? If the task are already loaded, JPA won’t need to fetch them when you access the collection.
Edit: The JPA 2.0 specification writes in section 4.4.5.3: