1

Recently I was asked a question which left me thinking..want to get the community views on the same question.

I have a CustomerEJB which has say a createCustomer method. My EJB is exposed as a web service and hence createCustomer is one of its operations.

When a request hits createCustomer, 2 operations need to be performed

  1. An INSERT SQL query into the database which may be adding certain data into db that came in input request
  2. creation of a text file, say .txt in the file system.

Now the question is I want to couple these two tasks into a transaction. If any one task fails, I rollback the other task as well.

Without mentioning any hot technologies, like Spring/Hibernate what is the approach I can follow for Transaction management

My thoughts: 1. I can use JTA, demarcate the transaction boundaries and perform commit and rollback accordingly. JDBC can be used for the SQL task 2. I can use DAOs

Inviting your kind suggestions/comments

HungryForKnowledge
  • 289
  • 1
  • 8
  • 18
  • http://stackoverflow.com/questions/892349/is-there-an-open-source-solution-to-xa-transactional-file-access-in-java – Uncredited Oct 18 '12 at 10:50

1 Answers1

1

You would need to wrap the file creating in a XA capable JCA connector (not sure whether there's a ready made one out there, a quick good only found this fsconnector which doesn't support transactions yet), and use an XA driver for your DB transaction (most DBs will will be able handle this) and then wrap your EJB in an XA transaction (should be straightforward).

As long as both resources can handle the XA transactions, you'll get the benefit of 2-phase commits, which is what you're after.

beny23
  • 34,390
  • 5
  • 82
  • 85