I have a factory which is a static class, instantiated via Spring
Within the Email class I have a save() method which uses the DAO to save the email. When I annotate the save method with @Transactional I expect that the transactions will run, since the Email object was created through Spring. However, I am finding that the transactions are not running. As part of the save a delete occurs on one piece of data, and a SQLException occurs later but the deleted data is still gone. Nothing was rolled back.Code:@Component public class CommunicationFactory implements BeanFactoryAware { // Main DAO private static CommunicationDAO communicationDAO; @Autowired(required = true) public void setCommunicationDAO(CommunicationDAO communicationDAO) { CommunicationFactory.communicationDAO = communicationDAO; } private static BeanFactory beanFactory; @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { CommunicationFactory.beanFactory = beanFactory; } public static Email createEmail() { Email email = (Email)beanFactory.getBean("emailBean"); // Set the DAO reference email.setCommunicationDAO(communicationDAO); return email; } }
I have added excessive logging and do not see anything about transactions being created. I have also scoured google, books, stackoverflow, forums etc... and have not found an answer. I feel like I am missing something obvious. Are there any other requirements for transactions or am I missing something else?
P.S. I do see transaction logs when I run the same method via a JUnit test and the error is rolled back. I also have transactions working in other beans which are directly created by spring.


Reply With Quote
