semangar wrote:
Question 3)
In chapter 11.1 you discribed 3 solutions to propagate the persistence context:
-> ThreadLocal
-> JTA
-> EJB-CMT
In chapter 16:
-> the caveat emptor application [native version] uses the OSIV pattern and none of the three previous strategies.
-> the caveat emptor application [JPA version] uses the stateless EJB-CMT strategy.
=> It was then not clear for me to decide which one to use, for which kind of architecture (2-tiers, 3-tiers; with or without conversation).
Could you summarize this please: what is possible, what is recommended?
Samuel
1. This is not correct, the OSIV native version in chapter 16 relies on ThreadLocal binding. The servlet filter starts a transaction, which binds the "current Session" to a ThreadLocal, and it commits a transaction, which unbinds the "current Session" from the ThreadLocal and closes it after flushing.
2. JPA does not support persistence context propagation unless you use injection by an EJB3 container, usually you then also use EJB-CMT. (Although it is possible to use JTA transaction demarcation with EJBs.) You can not get any kind of EntityManager propagation with JPA, if you are not using EJBs.
3. This is all summarized in the book, you need to read these chapters again. Yes, I know it's quite complicated... my recommendation is to pick the environment you are going to work in and read what is supported there. If you can pick any environment, use JBoss Seam, which simplifies and unifies all that stuff.