-
1. Re: PersistenceContextType.EXTENDED and Transactions
wdfink Dec 14, 2010 5:41 AM (in response to brandx)As i understand the EXTENDED persistence context ...
The persistence manager is under user/programmer control, in this case it makes no sense to use it with a stateless bean it will break the contract.
You might use it together with a stateful bean to have all data across multiple call (e.g. web formular with many pages) and commit only if the last access is successful. Transaction can also used, but you should limit the Tx scope because of timeouts and locks.
-
2. Re: PersistenceContextType.EXTENDED and Transactions
brandx Dec 14, 2010 1:07 PM (in response to wdfink)I am using it in a stateful bean.
But what exactly is the syntax for starting and stopping a transaction? All of the methods that I've been able to discern either result in an error or in no data being written to the database.
-
3. Re: PersistenceContextType.EXTENDED and Transactions
brandx Dec 14, 2010 1:50 PM (in response to brandx)Hm, well I found http://bill.burkecentral.com/category/jpa/, which says that I can use EXTENDED on an org.hibernate.Session and then use that instead of an EntityManager. I tried that, and was thence able to call Session's beginTransaction() and org.hibernate.Transaction's commit() method without error, and data was persisted to the database. Presuming that it's actually doing what it says, I guess that's my solution for the time being. I would have preferred to have stayed in standard JPA though, so if anyone knows how to do what I was trying to do in JPA, please let me know.
-
4. Re: PersistenceContextType.EXTENDED and Transactions
brandx Dec 14, 2010 2:06 PM (in response to brandx)Heh, and I just found yet another way to do it.
@Stateful
@TransactionManagement(value=TransactionManagementType.BEAN)
public class X implements IX {
@PersistenceContext(unitName="MySQL", type=PersistenceContextType.EXTENDED)private EntityManager em;@Resourceprivate UserTransaction tx;@PersistenceContext(unitName="MySQL", type=PersistenceContextType.EXTENDED)
private EntityManager em;
@Resource
private UserTransaction tx;
public void doStuff() {
tx.begin();
em.joinTransaction();
...
tx.commit();
}
}
Which is JPA compliant and does seem to work.