How to implement AuditorAware with Spring Data JPA and Spring Security?

前端 未结 4 1568
星月不相逢
星月不相逢 2021-02-01 19:29

We use Hibernate/JPA, Spring, Spring Data and Spring Security in our application. I have a standard User entity which is mapped using JPA. Further, I have a U

4条回答
  •  孤独总比滥情好
    2021-02-01 20:09

    I got the same issue and what I did was just change the propagation on the findByUsername(username) method to Propagation.REQUIRES_NEW, I suspected that was a problem with the transactions, so I changed to use a new transaction and that worked well for me. I hope this can help.

    @Repository
    public interface UserRepository extends JpaRepository {
    
        @Transactional(propagation = Propagation.REQUIRES_NEW)
        List findByUsername(String username);
    }
    

提交回复
热议问题