Hi,
In my spring project, I'm using a class of "Interactive Brokers" and I explicitely annotate this class with @Component. This class is going to write into the DB via methods of a CRUDService (Spring bean), so I annotate all methods of the I.B. class with : @Transactional(propagation = Propagation.REQUIRES_NEW).
PHP Code:
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class RequestRealTimeBarsIB extends RetrievalBase {
@Autowired
private CRUDService crudService;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void realtimeBar(int reqId, long time, double open, double high, double low, double close, long volume, double wap, int count) {
...
crudService.create(...);
}
CRUDServiceBean.java
PHP Code:
@Repository
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Transactional(propagation = Propagation.MANDATORY)
// Above will simply ensure that a transaction has already been started when the DAO layer is entered
public class CRUDServiceBean implements CRUDService {
@PersistenceContext
private EntityManager em;
public EntityManager getEntityManager() {
return em;
}
public <T extends BaseEntity> T create(T t) {
em.persist(t);
em.flush();
em.refresh(t);
return t;
}
The methods of RequestRealTimeBarsIB are called by Interactive brokers service automatically every 5 seconds.
The Problem is that the create method of CRUDService is throwing an exception :
HTML Code:
"No Excisting transaction found for transaction marked with propagation 'mandatorry'
How can I make sure that a transaction is started regardless how the method realtimeBar(..) is called ?
Many thanks,
Frank