Reputation: 125
I am wondering why do we use stateless annotation when using TransactionAttributeType, like so:
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Stateless
public class Controller {
Any help is appreciated, thanks!
Upvotes: 0
Views: 1104
Reputation: 693
@Stateless determines the type of bean (one that does not maintain a conversational state with the client). @TransactionAttribute determines the way to handle transactions. In your example the bean won't hold client-specific state after the end of invocation. But when you choose REQUIRES_NEW it will always create a new transaction for each method invocation (in contrast to default REQUIRED when existing transaction can be used and if it doesn't exist it will be created by container).
Upvotes: 1