-
1. Re: Caching in a long running conversation
asookazian Sep 5, 2009 12:19 AM (in response to trossmy)Seam-managed persistence context (SMPC) is a conversation-scoped, extended PC. The PC serves as a 1st level cache (this is what enables us to queue changes to entities and flush them all at the end of the LRC/transaction, thereby minimizing db round trips). So whenever you load some entities, say via a createQuery() call, those entities are managed by the PC and are in the 1st level cache.
When you end the LRC, the SMPC is destroyed by the Seam container. Assuming that the PC was flushed (typically via AUTO or MANUAL) prior to the end of the conversation, and the tx was successfully committed, then the CRUD operations queued in the PC are executed from you persistence provider via the JDBC driver to your RDBMDS.
If you want more details on all this, read JPA/Hibernate or SiA books.
Check out this class in the core Seam codebase if you want to know how it works (you can add debug brkpts to see what is happening when): org.jboss.seam.persistence.ManagedPersistenceContext
-
2. Re: Caching in a long running conversation
asookazian Sep 5, 2009 12:20 AM (in response to trossmy)Also, the Yuan 2nd ed. Seam book has a very good section on caching strategies (1st and 2nd level).
-
3. Re: Caching in a long running conversation
asookazian Sep 5, 2009 12:32 AM (in response to trossmy)This is a very good article on L1 and L2 caching in JPA 2.0:
http://weblogs.java.net/blog/caroljmcdonald/archive/2009/08/jpa_caching.html
-
4. Re: Caching in a long running conversation
asookazian Sep 5, 2009 12:42 AM (in response to trossmy)Another very good one on MySQL: http://blogs.sun.com/carolmcdonald/entry/mysql_for_developers
-
5. Re: Caching in a long running conversation
trossmy Sep 7, 2009 11:57 AM (in response to trossmy)thanks Arbi for the detailed answer...does that mean I have to give up the idea of having updated entities while the LRC is still alive?
-
6. Re: Caching in a long running conversation
trossmy Sep 7, 2009 6:38 PM (in response to trossmy)So, as far as I understand the entities are cached in the first-level cache, which is the persistence context. So before I execute the query I can call entityManager.clear, and I get fresh entities. But then all entities in the LRC are detached, right? And I might run into lazy initialization exceptions?
-
7. Re: Caching in a long running conversation
trossmy Sep 7, 2009 6:47 PM (in response to trossmy)anyway, calling entityManager.clear before executing the query seems to be the solution for my app...haven't run into any problems so far.