0

In short... I have the following case:

@Stateless
@Local(A.class)
@TransactionAttribute(TransactionAttributeType.MANDATORY)
Class A{
   ...
}

@Stateless
@Local({ B.class })
@Specializes
@TransactionAttribute(TransactionAttributeType.REQUIRED)
Class B extends A{
   ...
}

The annotation @TransactionAttribute(TransactionAttributeType.REQUIRED) is not applied to the methods of the class B. Those methods do not override methods of class A and they are public and are being called from the client.

IMHO this should work but it doesn't. It seems the TransactionAttribute annotation is taken from the class A and it seems the only way to set the REQUIRED transaction type, is to put the annotation at method level . Why is that?

UPDATE: I also noticed that not even the same (in my case MANDATORY) transaction attribute works.

Thanks!

danizmax
  • 2,446
  • 2
  • 32
  • 41

1 Answers1

1

Look at this https://stackoverflow.com/a/5542890/2370742

EJB 3.1 section 13.3.7.1 also explicitly states the rules for @TransactionAttribute:

If the bean class has superclasses, the following additional rules apply.

  • transaction attribute specified on a superclass S applies to the business methods defined by S. If a class-level transaction attribute is not specified on S, it is equivalent to specification of
    TransactionAttribute(REQUIRED) on S.
  • A transaction attribute may be specified on a business method M defined > by class S to override for method M the transaction attribute value > explicitly or implicitly specified on the class S.

According that, the annotation at class level, only apply to this class methods not it's child class. You must use in class B

@TransactionAttribute(TransactionAttributeType.MANDATORY)
Class A{
  public void methodX1(){}
  public void methodX2(){}

}

@TransactionAttribute(TransactionAttributeType.REQUIRED)
Class B extends A{
  @TransactionAttribute(TransactionAttributeType.SUPPORTS)
  public void methodX1(){
  //supperts as defined in this method
 }

  public void methodX2(){
  //mandatory as defined in superclass
  }

  public void methodX3(){
       // required as defined in this class
  }
}
Community
  • 1
  • 1
  • I don't see any relevance of these rules in my implementation. It just says that transaction attribute applies only to its class. You actually removed the bulletpoint of the link that could explain my problem... it says "If a method M of class S overrides a business method defined by a superclass of S, the transaction attribute of M is determined by the above rules as applied to class S", but still I defined transaction attribute on class level on both classes which with my interpretation should override transaction attribute definition from super class. – danizmax May 18 '15 at 08:12
  • Yes you are right. I am trying your example (on Glassfish4.1) and I have a question ¿How are defined your classes? ¿As EJB Local View? ¿Local EJB? ¿Or transactional CDI beans? – Mart Dominguez May 19 '15 at 12:09
  • I updated my question. My question does not exactly describe what I want to do, but it still describes the same problem. Basically what I want to achieve is to set classes A and B to MANDATORY on class level and then add methods to B that don't override anything and set them to REQUIRED. – danizmax May 20 '15 at 04:28