[jboss-user] [JBoss Seam] - Re: @Begin and @End
gavin.king@jboss.com
do-not-reply at jboss.com
Wed Jul 19 14:13:51 EDT 2006
If you really _have_ to have transparent lazy fetching of data off of the user, combined with caching of that data then create a session-scoped managed persistence context.
There are a couple of ways to do this, but the easiest is to use Seam 1.1 CVS build and throw the following in components.xml:
<component name="userDatabase"
| scope="session"
| class="org.jboss.seam.core.ManagedPersistenceContext">
| <property name="persistenceUnitJndiName">java:/myEntityManagerFactory</property>
| </component>
Alternatively, an approach I prefer is to only store the userId in session scope, and create a conversation-scoped manager component for the actual User, ie:
@Scope(CONVERSATION)
| @Name("user")
| public class ManagedUser
| {
| @In(create=true)
| private EntityManager myDatabase;
|
| @In String userId;
|
| @Unwrap
| public User getUser()
| {
| return myDatabase.find(User.class, userId);
| }
| }
Now, of course you won't get caching of the 100 dependent objects in the session scope, but they do at least get cached in the conversation scope. You will never experience LIEs, as long as you always refer to the dependent objects by injecting the User and then navigating.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3959267#3959267
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3959267
More information about the jboss-user
mailing list