Java – Spring ignores @Transactional annotations

Spring ignores @Transactional annotations… here is a solution to the problem.

Spring ignores @Transactional annotations

In one of our projects, we encountered an issue where Spring ignored @Transactional comments and then failed with the following error.

Error starting ApplicationContext. To display the conditions report
re-run your application with ‘debug’ enabled. 2018-09-13 15:05:18,406
ERROR [main] org.springframework.boot.SpringApplication Application
run failed org.springframework.dao.InvalidDataAccessApiUsageException:
No EntityManager with actual transaction available for current thread
– cannot reliably process ‘remove’ call; nested exception is javax.persistence.TransactionRequiredException: No EntityManager with
actual transaction available for current thread – cannot reliably
process ‘remove’ call at

I found a similar issue, but none of the solutions work for this situation.

  • @EnableTransactionManagement exists
  • Transaction classes implement interfaces
  • The trading method is public
  • Transactional methods are not called internally

When I annotate CacheService with @Transactional, everything is back to normal again. But I’m trying to understand why Spring ignores @Transactional on CacheAService.

I tried logging Spring’s transaction interceptor, but didn’t mention CacheA. This is the only relevant content that is logged.

2018-09-13 15:05:18,242 TRACE [main]
Don’t need to create transaction for
This method isn’t transactional.

This is simplified code. Spring’s ContextRefreshedEvent calls code during application startup.

public class CacheService implements Cache {

    private CacheA cacheAService;
    private CacheB cacheBService;

    public void clearCache() {

public interface CacheA {
    void deleteShortTermCache();

@Transactional(readOnly = true)
public class CacheAService implements CacheA {

    private CacheARepository cacheARepository;

    public void deleteShortTermCache() {

public interface CacheB {
    void deleteAll();

@Transactional(readOnly = true)
public class CacheBService implements CacheB {

    private CacheBRepository cacheBRepository;

    public void deleteAll {

public enum CacheValidity {

public interface CacheARepository extends JpaRepository<CacheItem, Integer> {
    void deleteByValidity(CacheValidity validity);

public enum CacheItemKey {

@Table(name = "cache_item")
public class CacheItem {

    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cache_item_id_seq")
    @SequenceGenerator(name = "cache_item_id_seq", sequenceName = "cache_item_id_seq", allocationSize = 1)
    private Integer id;

@Column(nullable = false, unique = true)
    private CacheItemKey key;

@Column(nullable = false)
    private String value;

@Column(name = "date_modified", nullable = false)
    private Date dateModified;

@Column(nullable = false)
    private CacheValidity validity;

public Integer getId() {
        return id;

public void setId(final Integer id) { = id;

public CacheItemKey getKey() {
        return key;

public void setKey(final CacheItemKey key) {
        this.key = key;

public String getValue() {
        return value;

public void setValue(final String value) {
        this.value = value;

public Date getDateModified() {
        return dateModified;

public void setDateModified(final Date dateModified) {
        this.dateModified = dateModified;

public CacheValidity getValidity() {
        return validity;

public void setValidity(final CacheValidity validity) {
        this.validity = validity;


After some digging, I found this in the logs.

2018-09-14 06:24:11,174 INFO [localhost-startStop-1]$BeanPostProcessorChecker
Bean ‘cacheAService’ of type [] is not
eligible for getting processed by all BeanPostProcessors (for example:
not eligible for auto-proxying)


We found that this issue was caused by Spring Boot’s automatic configuration. Since automatic configuration already sets up transaction management, our @EnableTransactionManagement custom configuration breaks the instantiation of Transaction Advisor. Removing @EnableTransactionManagement from our config solved the problem.

Related Problems and Solutions