This content has been marked as final.
Show 3 replies
-
1. Re: Lazy Instatiation Exceptions...
tony.herstell1 Aug 9, 2008 8:14 PM (in response to tony.herstell1)I can now get the image up; but only the first time the page is displayed.
If I click on "page 2" on the rich:datascroller I get lazy exception.
I have fiddled and fiddled but really don't know why as SEAM promises NO lazy exceptions!
this is the code that diplays the image:<s:graphicImage rendered="#{eachUser.avatar ne null}" value="#{eachUser.avatar.image}" />
This is the code that manages the processing:/** * @author Tony Herstell * @version $Revision: 1.1 $ $Date: 2008-08-09 10:54:57 $ */ @SuppressWarnings("serial") @Stateful @Name("userListController") @Conversational public class UserListControllerImpl implements UserListController, Serializable { /** * Inject and leverage the Seam Logger. */ @Logger private Log log; /** * Inject the EJB3 Persistence context in EXTENDED mode so will remain * "current" over multiple client/server round trips. */ @PersistenceContext private EntityManager em; @DataModel private List<User> userList; @Factory("userList") @TransactionAttribute(TransactionAttributeType.REQUIRED) public void findUsers() { userList = em.createQuery("from User user order by user.surname asc").getResultList(); } @TransactionAttribute(TransactionAttributeType.REQUIRED) @Begin public String enter() { return "userListController"; } @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @End public String cancel() { log.info(">cancel"); log.info("<cancel"); return "home"; } @Remove @Destroy @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void destroy() { log.info("> destory"); log.info("< destory"); } }
Here is my (possibly flawed" understanding:
em keeps track of the "link with the database" and is handled by seam so that it is re-inserted each time it is required avoiding lazy exceptions.
The factory gets called when userList is first used and populates it. As the bean is Conversational scope then it will only be created for a conversation and re-created for subsequent conversations (so re-reads from the Dbase for each conversation).
TransactionAttributeType.REQUIRED is needed for the Factory; but doesnt seem to make a difference for any other methods (can't even remember why I do this - Was in Micheal Yuans book to reduce transation overhead I think!)
Why is em not set back up by seam/RF when RF datascroller initiates a re-render of the next set of Users? -
2. Re: Lazy Instatiation Exceptions...
tony.herstell1 Aug 9, 2008 8:49 PM (in response to tony.herstell1)From reading this post (Seam)...
http://www.seamframework.org/Community/EntityManagerInjectionJPAHibernateTomcat
Is it possible that the em is not being re-injected properly as per his discussion. -
3. Re: Lazy Instatiation Exceptions...
tony.herstell1 Aug 11, 2008 3:12 AM (in response to tony.herstell1)Solved
Didnt have (type=PersistenceContextType.EXTENDED)
@PersistenceContext(type=PersistenceContextType.EXTENDED)