1
//--Service class--

@Service
public class myService implements myInterface {

    @Autowired
    private MyDao myDao;

    //some code
    myDao.updateMethod(/*some arguments*/);
    //some code   
}

//--Dao class--

@Repository
public class MyDao {

    @Transactional(transactionManager = sample_a)
    public void updateMethod(/*some arguments*/){
        newUpdateMethod(/*some arguments*/);
    }
    @Transactional(transactionManager = sample_a)
    public void newUpdateMethod(/*some arguments*/){
        /* Actual call to DB taking place */
    }

}

When I call updateMethod from service class it is giving transaction related exception- InvalidDataAccessApiUsageException - No transaction is currently active, Am I using @Transactional in right way? I also read somewhere @Transactional should not be used in class with @Repository annotation, but I have other methods with @Transactional in Dao class and they are working fine.

Devender Kumar
  • 107
  • 1
  • 12
  • 1
    https://stackoverflow.com/questions/1079114/where-does-the-transactional-annotation-belong – Adil Shaikh Dec 05 '19 at 16:02
  • When asking about an exception, you need to post the actual code causing it, and its complete and exact stack trace. Debugging partial pseudo-code is impossible. – JB Nizet Dec 05 '19 at 16:27
  • @JBNizet The code and stack trace is complicated for me and big to put here. Can you give your views about the flow of the code? – Devender Kumar Dec 06 '19 at 05:37

1 Answers1

0

The above code is working fine, the problem was in transactional manager. I was using a different transactional manager. The table that I was using to update data was in different database.

Devender Kumar
  • 107
  • 1
  • 12