79572983

Date: 2025-04-14 11:04:45
Score: 0.5
Natty:
Report link

What you need, is to to tell Java EE to use a new transaction for your methods. The easiest way is to have a method with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW):

@Stateless
public class ControlService {
   @EJB
   private TradeService tradeService;

   public void processPositions() {
       for(Position position : shortPositions) {
           tradeService.processPosition(position);
       }
   }
}

@Stateless
public class TradeService {
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public String processPosition(Position position) {
        // ... here is your business logic
    }
}

The first method, ControlService.processPositions() runs in the first transaction and each TradeService.processPosition() will have its own one.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): What you
  • Low reputation (1):
Posted by: Petr Aubrecht