I use CMP and want to set the Transaction (commit) within a method explicitly.
I have a method persisting 500 records in ONE Transaction.
I want to commit the transaction after 10 records (!) are inserted.
How could I do it? With UserTransaction? I have no clue. But this does not work. I have only ONE Transaction, but I want that a Transaction should be commited after 10 records are inserted and begins a new Transaction with the next 10 records..
posted 11 years ago
I have also tried it with Hibernates:
What is wrong, why can I not split my Transactions??
Your probably off getting hold of a copy of the book but some quick notes ..
Their bean is annotated NOT_SUPPORTED for transactions , they inject an extended persistence context / entity manager, they do all their db work in a normal (NOT_SUPPORTED) method (as much as you like uncommitted) and then have another method like the one below ...
I don't want to post the listing as its from a book but ...
The entity(s) are committed to the database when the extended persistence context is enlisted in a transaction when the commitToDB method is called, the flush isn't needed as the context joins the transaction when the method is called.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
posted 11 years ago
I do not get you. You mean, I should it change to @TransactionAttribute(REQUIRED) ??
nimo frey wrote:yes, the transaction is by default container-managed (@TransactionAttribute(TransactionAttributeType.REQUIRED))
But in this special case, I want to manage the Transaction-Cycle by my own. So I tried it with UserTransaction or HibernateTransaction, without success.
So when you call this method you start a new transaction (or join one if it already exists). Which means all transaction behaviour will be governed by the enclosing transaction - your transaction cannot commit until this does.
If you wan't to manage the transactional behaviour yourself you cannot also use CMT. Use NOT_SUPPORTED as Chris suggests.