Results 1 to 9 of 9

Thread: How to make a non Spring Class part of a Transaction

Threaded View

  1. #1

    Default How to make a non Spring Class part of a Transaction

    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 reqIdlong timedouble opendouble highdouble lowdouble closelong volumedouble wapint 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 <
    extends BaseEntityT 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
    Last edited by fv967; Oct 11th, 2012 at 03:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •