3

I'm using Spring Boot with Solr.
I can see Spring-tx in my resolved dependencies.
When I call a @Transactional annotated method in a Spring bean,
a) at runtime, i don't see any signs of it being wrapped in any transaction management proxy, and
b) when the method throws a RuntimeException the data is not rolledback.

The email/phone repositories and just interfaces that extend

org.springframework.data.solr.repository.SolrCrudRepository

What am i missing?

At have the method annotated @Transactional in both the interface and the implementation, just in case ;-)

public interface MyServiceInterface {

    @Transactional
    public CreateDetailsResponse createAllDetails(
            final CreateDetailsRequest createDetailsRequest) throws BusinessException;
}
public class MyService implements MyServiceInterface {

    @Autowired
    private EmailRepository emailRepository;

    @Autowired
    private EmailRepository phoneRepository;

    @Transactional
    public CreateDetailsResponse createAllDetails(
            final CreateDetailsRequest createDetailsRequest) throws BusinessException {

         //method below calls emailRepository.save(emailDocument) 
         saveEmail(); 

         //method below is supposed to call phoneRepository.save(phoneDocument) 
         //but throws RuntimeException before save is called
         savePhone(); 
    }
    //...
}

@Configuration
@EnableSolrRepositories(basePackages = "com.....repository", multicoreSupport = true,
        considerNestedRepositories = true, repositoryBaseClass = SoftCommitSimpleSolrRepository.class)
@EnableAutoConfiguration
public class ConsumersServiceConfiguration {
   //...
   @Bean
    public MyServiceInterface myService() {
        return new MyService();
    }
}

dependencies included from my pom

Supposedly Solr supports transactions:

enter image description here

inor
  • 2,781
  • 2
  • 32
  • 42
  • Does the spring-boot transaction module require transaction support in the storage layer (I'd guess so)? As there is no such thing in Solr, that could be your issue. – MatsLindh Oct 25 '18 at 08:55
  • @MatsLindh just added ref to Spring doc'n that seems to indicate that Solr supports transactions – inor Oct 25 '18 at 09:02
  • Ah yes, my bad. Documents can be rolled back or committed, but there is no transactional separation. If a separate thread adds documents and issues a commit, the documents added from your thread will also be committed to the index. – MatsLindh Oct 25 '18 at 09:11
  • It will be helpful if you can publish all the related code changes for example - where are you autowiring this service, where are you calling this service method, where is saveEmail and savePhone mehtod declared and how are you calling these methods. While dealing with Spring annotations these things will matter. Perhaps you should annotate your ServiceImpl class with @Service. Take a look at this thread - https://stackoverflow.com/questions/4396284/does-spring-transactional-attribute-work-on-a-private-method – saurav Oct 25 '18 at 10:11
  • @surav, i've added more info about the repositories used. Can't any public method of any Spring bean be annotated as @Transactional? does it have to be @ Service component? – inor Nov 01 '18 at 06:00

0 Answers0