Reputation: 43
I am using EJB in order to take advantages of:
Concurrent (instead of creating 2 threads, I divided the work into 2 EJB beans).
Pooling (I use stateless EJB a lot and I love the idea that the pool contains a specific number of bean). This way, I am not afraid of running out of memory. Memory usage is more predictable).
Asynchronous processing (all I need is just an annotation).
Well, the problem is I am using it with MongoDB so I don't need any transaction. I can use @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
and @TransactionAttribute(TransactionAttributeType.NEVER)
annotations but... it means I must specify it everywhere?
Is there anyway to disable EJB transaction by default?
Upvotes: 4
Views: 8645
Reputation: 2711
In an EJB 3.0 container, annotate your EJB (or EJB method) with:
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@TransactionAttribute(value=TransactionAttributeType.NEVER)
public class YourBean
for BEAN management. For CONTAINER management instead:
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(value=TransactionAttributeType.NEVER)
public class YourBean
Upvotes: 9
Reputation: 300
The default value is managed by the container but if you dont specify nothing to do i think you solve your problem.
Or annotate all the Ejb to don´t support transaction
@Stateless
@TransactionManagement(TransactionManagementType.NEVER)
public class YourBean
Remember that the ejb transactions are executed in a hierarchical way, ie if the first method being invoked does not support methods "children methods" are handled in the same way
Upvotes: 1