• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

J2EE transactions - stateless beans (CMT)

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Background
----------------------
We have a back end job that is calling a Stateless EJB (service) to process a list of entries (in an excel file). Each entry in the file represent a set of tables in the DB. Hence a record would comprise of data that would be stored in, say, 6 tables. This is basically an entry for subscribing an user to a product and also store the payment, invoice details of the subscription.

The file contains around 200 records to be subscribed, each for different users.

Problem context
---------------------
Each entry in the file are processed and stored in the DB in a single method (let me call it "processEntry") in the EJB. This EJB is defined as Container managed and also a transaction attribute is set to RequiresNew for the method "processEntry". This method is called in a loop to process each entry in the file. Our understanding with CMT is that once the method under a transaction is completed, the changes are committed to the database but what happens is that, after all the records are processed only then it commits all these records. The problem we have here is that, there are certain entries that would require to check if its parent entries are successfully inserted into the DB and also retrieve its ID. Since all the entries are committed only at the completion of the service, our check fails. Hence we would like to know:

1) what is wrong in our understanding that each time the method is called the transaction is completed and should commit the records. This doesn't seem to happen in this case

2) What is the best practise for batch processing and especially in the above case where you need to get information of the recently inserted data while processing all the entries

Also, we are using Spring-Hibernate with JTA for our DB related operations.


Technologies used
------------------------
J2EE
Hibernate 3.0.5
Spring 2.x
JBoss 4.0.2
Struts / JSP

Appreciate if you could throw some light on this.

Thanks,
Srini
 
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


Our understanding with CMT is that once the method under a transaction is completed, the changes are committed to the database but what happens is that, after all the records are processed only then it commits all these records.


It sounds like you have somehow wrapped all your EJB method calls in a transaction. Not sure how you've managed this given what you say, but RequiresNew should be suspending any existing (client) transaction, starting its own transaction, committing or rolling back, then restarting the existing transaction (if it existed). What you have sounds like you are using the Required trans attribute.

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Paul here. Just double check your transaction type, if it is RequiresNew it should commit after each method in your loop. However, if you want to ensure your changes are reflected before a commit occurs you can always call flush() on your EntityManager (assuming your using JPA).
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic