It does seem that we aren't quite understanding each other.  Let me clarify a 
few points that I think might help you.

1) So I don't confuse things (including myself) I'm going to pretend that 
Persistence Context and Entity Manager mean the same thing.  
@PersistenceContext(type=EXTENDED) does not provide an EM scoped to the 
conversation, because it is not aware that conversations exist.  This confused 
me at first too because there is a lot of new information to take in.  First 
you have the EJB3 spec and the EM propagation rules there, and then you have 
your Seam Managed EM with it's own rules.  What you get by using 
@PersistenceContext(type=EXTENDED) is an EM that will survive from call to call 
on the session bean where it's defined, even if those calls span requests.  It 
will also be propagated through to other session beans called by the original.  
That might be an oversimplification but I think you get the gist.  What you get 
with a seam managed persistence context is a single EM per conversation which 
can be injected using @In.

2) Once you've got your Seam Managed EM set up it will act as an object cache 
over the course of the conversation, only hitting the database for object 
retrieval when it has to.  So if you retrieve a User as soon as the 
conversation is started, every time you call em.find(User.class, userId) 
afterwards you get the cached user back.  No extraneous queries.  The EM will 
also check to see which objects have been updated and generated the appropriate 
sql once it is flushed.

3) I see 2 reasons off the top of my head not to use a session scoped EM.  The 
first is that you are caching data that the user has accessed throughout their 
session when much of it is quite possibly no longer relevant.  Why take up the 
extra memory?  I see no real benefits to this approach and even if your app is 
small enough that it doesn't make a difference now, it's not going to be very 
scalable.  The second is a matter of providing accurate data.  In my opinion 
it's a good thing to drop your entity manager at a well defined point (when the 
data in it is no longer being used) so that if the user chooses another 
operation that relies on that data a fresh, up to date version of it will be 
retrieved.  If you use the same entity manager throughout a user's session they 
will only see any changes that they have made (which are retrieved from their 
EM cache).



View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3984165#3984165

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3984165
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to