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