• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean managed Transaction for Entity Beans

 
s khosa
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can someone please explain why Entity Beans can not use Bean managed Transaction. As per the explanation given in the book it says, since ejbLoad and ejbStore are called by container at will and not controlled by entity bean....Entity bean can not use Bean Managed Transaction.

But could an Entity bean not call begin() in ejbCreate()/ejbActivate() and commit in ejbPassivate()???

Thanks
 
Ricardo Ferreira
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by s khosa:
Hi,

Can someone please explain why Entity Beans can not use Bean managed Transaction. As per the explanation given in the book it says, since ejbLoad and ejbStore are called by container at will and not controlled by entity bean....Entity bean can not use Bean Managed Transaction.

But could an Entity bean not call begin() in ejbCreate()/ejbActivate() and commit in ejbPassivate()???

Thanks


Khosa,

First, in EJB, Beans only can have your transaction strategy controlled by the container, because, it knows WHEN should it have to release some resources, and WHEN to start and finalize the transactions. This could be easylly done by transaction attributes.

Second, Call a beginTransaction() in the ejbActivate(), and call commit() on the ejbPassivate() or ejbRemove() of the Bean, you are explicity freeing your solution of two principals non functionals requirements:

- Scalability
- Availability

Well, let me show some issues for this approach. You know that the container, passivate a SFSB or Entity bean, to free some resources that are not being used by a period of time. But, when it does this, you cannot see, because it's a container service. Now, supouse that you start a JTA transaction some time, and, this transaction only will be released in the passivation.

But, depending of the demand, this could evaluate 5 or 6 hours from the start time. You would maintain a expensive resource as an transaction loocked for all this time? You are losting precious container resources.

Transactions should be focused, demanding only a request time of a simple use case service, as create an customer account, insert an customer in the flights list, etc.

So, the answer is that: The Entity beans just only can use CMT, because the container, knowing of this resouce managements, will take are for you. All the life cycle of entities, are controlled by the container, to ensure scalability (a key point of j2ee), and transactions and thirdy party resources as JDBC Datasources, should be controlled by it too.

note..: Transactions are expensive because there are two resources being used. The container's transaction schema's, and the database (EIS TIER), transaction segment. This show's you another impact of a bed management of this resources: affect the eis tier, looking resources for a big period of time. Some DBA's could kill you for this
 
s khosa
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ricardo. I understand what you are saying. I was more interested in knowing would this vioalte any EJB container ENFORCED rule? From design perspective, yes it SHOULD NOT do it. But i am confused whether it COULD NOT...:-)))). More from coding rules perspective.

Thanks
 
Raghubir Bose
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going thru' Ed Roman and suddenly found this..may be this would be more programmatic in nature.
When you call an entity bean in a transaction, the first action that happens is that,the entity bean tries to load the database data thru' the ejbLoad method.This method acquires locks in the database and ensures that the entity bean cache is consistant.Then the other business methods are called.When the transaction is committed, the entity beans ejbStore method is called, which writes the updates to the database, and releases the locks.So the order is ejbLoad -- > business methods --> ejbStore.

If we use BMT, we would write code to do begin() and commit() methods inside our bean(using jdbc or some data access technology).

Perhaps what we would do is start the transaction in ejbLoad and end it in ejbStore().The problem here is that ejbLoad and ejbStore is not called by us, it is called by the container.The bean cannot enforce that the order of the call is ejbLoad --> ejbStore.So if we start a transaction in ejbLoad, the transaction might not end, since when the ejbStore will be called in not in our hands.

Because of this reason BMT for entity beans is not legal.

--Bose.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic