Hi, I did send down a question a couple of weeks ago on javaranch,but got no positive response. However ill put it again.Thanx to anyone who helps in advance. 1.How do i connect my ejb to a blob.COde will be appreciated. 2.When we can create and rollback a transaction ourselves using preparedstatement etc etc why do we use EJBs. 3.How do i guess which transaction attribute to use when i write an ejb.I have used Required and requires new. i know the reason for these two,but what bout the others. Deepak.
1. This is really a JDBC question and suggest you post it there. (I am too lazy to do the answer justice ) 2. One of the major benefits of EJB is declarative transaction management. If you need to change the way transactions work than it just requires changing the deployment descriptors. Plus most J2EE Application Servers support 2PC commit out of the box. This is a definite advantage over just JDBC, sure you could do the transaction stuff but it is messy, inflexible, and changing it is a pain. 3. Different types of transaction attributes in EJB:
Required - Always runs in a transaction. If a transaction is currently in progress the ejb will join, if there is no transaction in progress than the container will create a transaction for the ejb to join.
RequiresNew - Container will always create a new transaction for this ejb or method any current transaction will be suspended until the new transaction completes.
Supports - Will join a transaction if no is in progress but will also work outside of a transaction if one is not in progress.
NotSupported - Will not join a transaction that may be in progress. Instead the transaction will be suspended until the bean completes, at which time it will resume.
Mandatory - A transaction MUST be in progress in order to call this bean. An exception will be thrown if called outside the context of a transaction.
Never Doesn't want anything to do with transactions. Will throw an exception if a transaction is in progress when this bean is called.
Joined: Oct 04, 2001
What is this 2PC out of box commit. Secondly dont u think using ejbs asks for an overhead. And thirdly, dear the blob part of it was an interview question.
Joined: Jul 18, 2001
2 Phase Commit is a protocol for distributed transactions. Out of the box means that it is built in to the server. No need for additional software to support it. Yes, ejb is additional overhead. But if you are doing a lot of transactions, especially distributed transactions, then it is much easier and more maintainable to use ejb.