Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction Management

 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am very much confused with transaction at service/application layer and transaction at DAO layer.
My question is What is the purpose of a transaction at a service layer?

Lets say for Example. I have shopping cart where the requirement says on successful payment of fee

1) the order information Should be sent to the shipping sector
2)Removing an item from the cart
3)Sending an email to the customer who ordered it

The basic principle is to put all the three under a single transaction. SO either all commits or rollbacks. but what confuses me is

Where to start this transaction, Should i start this transaction at Service layer in session beans or at the dao layer with entity beans?

With EJB, If i start my transaction at the service layer containing session beans, this can be propagated to entity beans so either all commits are roll backs, if some failure occurs

but what happens if i integrate my application with Hibernate instead of entity beans for persistence,Now I am aware that hibernate transaction should be used for

persistence instead of EJB transaction.

my question is in this scenario what is the purpose of starting a transaction in session bean when we use hibernate transaction.


Thanks,
Shyam.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"I am very much confused with transaction at service/application layer and transaction at DAO layer."
-- While understanding transactions, you need to understand what is a resource manager? types of transactions --> RMLT, Global transaction, Sessions, Unit of Work (specifically what is the difference between transactional Unit of Work, Hibernate Unit of Work, etc.,), transaction demarcation mechanisms.

"My question is What is the purpose of a transaction at a service layer? "
-- Because you service can be spread across multiple Resource Managers (Database being one!!)

My quick suggestion is to read a nice book. Especially the sections related to transactions in EJB, Hibernate.
Further if you are interested, you can read about spring transaction.

"my question is in this scenario what is the purpose of starting a transaction in session bean when we use hibernate transaction. "
-- Read about RMLT, CMT, BMT. Googling would give you some nice documents.
 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Arun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic