Re: EJB Transaction
gk wrote:
This is from Book "Ejb 3.0 In Simple Steps" By Drearntech Press
I have gone through the EJB Transaction Attributes . I know there are
Six transaction attributes we all know REQUIRED ,
REQUIRED_NEW ,MANDATORY , NOT_SUPPORTED, SUPPORTS and NEVER.
My question is on its usage .....see what the Book says ...Here is
the excerpt from the Book
REQUIRED
--------------------------
The REQUIRED transaction operation is required when the method is
involved in some serious data change which needs to be protected by a
transaction.
My Question>> : I'm not sure what does the Book mean by "some
serious data change" ....To me , any data change is a serious
The book was being shamefully imprecise and poorly written. See Robert
Klemme's answer. Bottom line, "serious data change" is not an engineering
concept. "Must participate in a transaction" is. You can determine
objectively whether a given set of changes must occur together or not at all,
and whether one such change is part of such a set that must occur together.
If it is, then a transaction is REQUIRED for that change to be meaningful.
matter :) ....So , this part is not clear. Does anybody have any idea
or real example when this could be useful ? may be in terms of code or
a case study to understand this concept.
The classic transaction example is a monetary exchange. Suppose Gunther
initiates a transfer of one million yuan to the account of Mr. Lew. Clearly
the removal of one million yuan from Gunther's account and the deposit into
Mr. Lew's must occur as a transaction, together or not at all. The two banks
presumably use different data stores and business systems, so a single-phase
commit is out of the question. One can and should require that the withdrawal
and the deposit occur within an XA (or similar) transaction.
MANDATORY
----------------------------
We should use the MANDATORY attribute when our method needs to verify
that the component was invoked within the context of a client-managed
transaction.
My Question>> : Again, "method needs to verify that the component was
invoked within the context of a client-managed transaction" is NOT
quite understandable . What is to be written for this verification in
code level ? may be in terms of code or a case study to understand
this concept.
What a terrible book.
<http://www.java-tips.org/java-ee-tips/enterprise-java-beans/introduction-to-the-java-transactio.html>
(found after two minutes with Google - have you tried that?)
explains it better. So does (gasp!) the official Java EE tutorial, of all things:
<http://download.oracle.com/javaee/6/tutorial/doc/bncih.html>
in particular,
<http://download.oracle.com/javaee/6/tutorial/doc/bncij.html#bncik>
The difference is that REQUIRED asks the container to start a transaction if
there isn't one, MANDATORY throws an exception if there isn't one.
--
Lew