• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

eplicitly begin and commit Transaction in CMP

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..


 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have also tried it with Hibernates:



What is wrong, why can I not split my Transactions??
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the method that calls this code already in a transaction?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the example you want is covered in ...

Enterprise Java Beans 3.0 pg 408 ..

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.

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not get you. You mean, I should it change to @TransactionAttribute(REQUIRED) ??

 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I have tried it with that:




but this:


returns always false, so I guess, there is only ONE Transaction.
reply
    Bookmark Topic Watch Topic
  • New Topic