• 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

How to deal with transaction??

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know it's a quite big topic, just want to know if there's any best practise I can follow.

Let me introduce the project architecture first.

The web application is clearly divided into three layers: presentation, business, and persistence.

In presentation layer, I use struts. In struts action classes, I call facades provided by business layer.

In business layer, I have a few facades represent a few modules. Calls between modules must call its facade. Within a module, there maybe a lot of classes implements business logic. All persistence related call would be forward to DAO interface, which is provided by persistence layer.

In persistence layer, there are a few DAO implementations represent their modules. In each DAO implementation, data accesses are encapsulated. No matter what persistence approach will be used, it's just a kind of implementation.

Say, if I use container-managed transaction. I�m not sure where the transaction starts and ends. Does it happen in facades? Or happen in individual classes in business layer? I know it cannot be in struts classes.

If we handle transaction by ourselves, where should we start and commit it? In struts action? Fa�ade? Or where?

I need your help, guys. I need to know what is the best practise and why?

Thanks and waiting for your reply.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The facade mentioned in the scenario,
Is it a session facade ?
If the answer is yes..


Regarding to the question, where the transaction starts in container manged transaction.
The transaction will be started at the facade level..
If the required transaction attributes are being specified for the Session bean.
This transaction can be propogated to the business classes and DAO classes..

It is advisable not to handle transactions by the developer and that is the responsibility of the container in this scenario..
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A transaction can start either inside or outside the EJB container. If possible, you want the former (in the interest of keeping transactions small). In this case, the facade method(s) which must run in a transaction must have the correct tx attribute declared in the DD, normally Required. (This is for CMT beans, better in most cases than BMT beans.) If you need to rollback, you must call setRollbackOnly() or throw a system exception such as EJBException from your bean, POJO or DAO. Oh, and if you call setRollbackOnly() from a POJO or DAO, you will need to give them access to the bean's EJBContext.

You need a UserTransaction object for transactions started outside the EJB container, ie from your struts action classes. Check your container provider's documentation on how to get a UserTransaction, once you have it you must invoke its begin() method. You then call the bean method, which will run in the same tx if its tx attribute is Required or Mandatory.
 
Sean Li
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply. I know what you guys mean. It's better let the container manage the transaction. I agree with that.

but, how about if I don't use ejb container? I don't have any ejb. and I use Jdo or Ojb such object-database mapping persistence. what should I do?

I still have web action -> facade -> business class -> DAO. I know I must have a transaction object to explicitly start and commit transaction. I just don't know when and where.

Please help me, thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic