Hibernate transaction annotations in source - difference between class and method usage level?

I am trying to understand what is the difference in behavior when applying transaction annotation to class vs. method (and at the property level even?). Does anyone have a solid connection for this, or maybe even catch these differences succinctly for me?

The hundreds of links I found regarding these annotations seem to discuss how to use them in configuration files rather than in the source. And in the rare case when the mention of them in the source is even mentioned, it is very worried.

Here is a concrete example of what I mean by class level:

@TransactionAttribute(TransactionAttributeType.REQUIRED) public class MyKickAssClass { } 

and its associated method level:

 public class MyOtherKickAssClass { @TransactionAttribute(TransactionAttributeType.REQUIRED) public void entryPointMethod() { //do some work, call other methods of this class, other fun stuff } 

I can guess what this behavior is in these cases, but finding concrete explanations and examples was a headache.

We use JBoss.

Thanks in advance.

+4
source share
1 answer

From JavaDoc:

An annotation can be specified in the bean class and / or can be specified in the methods of the class, which are methods of a business interface or presentation without an interface.

Specifying the TransactionAttribute annotation in the bean class means that it applies to all applicable business methods of the class. Indication of method annotation applies only to this method. If the annotation is applied both at the class level and at the method level, the method value overrides if the two do not agree.

http://download.oracle.com/javaee/6/api/javax/ejb/TransactionAttribute.html

I also recommend reading the Java EE tutorial:

http://download.oracle.com/javaee/6/tutorial/doc/bncih.html

+7
source

Source: https://habr.com/ru/post/897663/


All Articles