• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deployment descriptor transaction attributes

 
Charles O'Leary
Ranch Hand
Posts: 54
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSR:220
13.3.7.2 Specification of Transaction Attributes in the Deployment Descriptor states the following:

If the deployment descriptor is used to override annotations, and transaction attributes are not specified for some methods, the values specified in annotations (whether explicit or defaulted) will apply for those methods.



Is there ever a time when transaction attributes are not specified (and/or defaulted)? Annotated transaction attributes aren't overridden by transaction attributes in the deployment descriptor under what conditions exactly? If possible, could you please provide any (simple and) concrete examples to help clarify?

 
Himai Minh
Ranch Hand
Posts: 1359
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p.174 of EJB in Action (2nd edition), It says " REQUIRE is the default..." which means @TransactionAttribute.REQUIRED is the default.
 
Charles O'Leary
Ranch Hand
Posts: 54
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
13.3.7.2 Specification of Transaction Attributes in the Deployment Descriptor

The following is the description of the rules for the specification of transaction attributes in the deployment
descriptor. (See Section 19.5 for the complete syntax of the deployment descriptor.)

Note that even in the absence of the use of annotations, it is not necessary to explicitly specify transaction
attributes for all of the methods listed in section 13.3.7. If a transaction attribute is not specified for
a method in an EJB 3.1 deployment descriptor, the transaction attribute defaults to Required.

If the deployment descriptor is used to override annotations, and transaction attributes are not specified
for some methods, the values specified in annotations (whether explicit or defaulted) will apply for
those methods.


In the context of the above, what's meant by the following:

If the deployment descriptor is used to override annotations, and transaction attributes are not specified
for some methods, the values specified in annotations (whether explicit or defaulted) will apply for
those methods.



More specifically:

Is there ever a time when transaction attributes are not specified (and/or defaulted)? Annotated transaction attributes aren't overridden by transaction attributes in the deployment descriptor under what conditions exactly? If possible, could you please provide any (simple and) concrete examples to help clarify?

 
Himai Minh
Ranch Hand
Posts: 1359
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When transaction attribute is not specified, then, by default, it is @TransactionAttribute(TransactionAttributeType.REQUIRED).

On p.416 of EJB in Action(2nd),

You used @TransactionAttribute to specify that the transaction attribute for a bean method be REQUIRE_NEW. If you want to override it to use REQUIRED, then use the following descriptor:
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>BazaarAdmin</ejb-name>
<method-name>getUserWithItems</method-name>
<method-params></method-params>
</method>
<transaction-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

 
Charles O'Leary
Ranch Hand
Posts: 54
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himai Minh,

I agree with your answers for your specific example. I am NEVER a big fan of the specifications. Where's Head First? (Sorry, I digressed.) Since they are the standard by which these exams are judged and possibly because it's late, unfortunately, I'm not connecting your example with my specific questions. If you have the patience, please help me connect the dots.


Ranchers,

My (possibly erroneous) interpretation is that the values specified in annotations (whether explicit or defaulted) will apply for
those methods INSTEAD OF the values specified in the deployment descriptor under certain conditions?

AND there are numerous contradictions in MY understandings within this one sentence of the specification:

* Since when did annotations override deployment descriptor?
* Because of defaults (REQUIRED in this case), what does it mean for a transaction attribute to be simply "unspecified" (or not defaulted)?
* ".... specified in annotations (whether explicit or defaulted) will apply ..." But, in the same sentence it says that somehow "transaction attributes are not specified"?

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charles,

I understand your confusion. The specifications are not always easy to read. Let me try to simplify things for you:

  • Transaction attributes in the deplyment descriptor always override the transaction attributes in annotations.
  • It is possible to override one method of a certain EJB in the deployment descriptor. If you do so, the other methods wil have the value of the annotation, or if not specified they will get the default: REQUIRED.
  •  
    Charles O'Leary
    Ranch Hand
    Posts: 54
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Got it! Thanks Frits Walraven and Himai Minh!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic