Why createEntityManager is called before my REST controller method

540 Views Asked by At

This is more of a Spring JPA (Hibernate) related issue than AspectJ one, I believe.

Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE, Hibernate v5.4.9.Final, Spring Data Repositories

I am trying to implement Multi-tenancy in my existing single tenant application.

  • The tenant is chosen by the users via front-end. The tenant id is stored in HttpSession.
  • An advice for Rest Controller methods, reads the tenant id and keeps it in a ThreadLocal variable.

Now I have to enable a Hibernate Filter using the tenant id. For this, an AspectJ advice for my Repository (interface extends JpaRepository) methods work, but gets executed for each repository method call from Service.

This post is about the following (identical) implementations where the advice for enabling Hibernate Filter is fired before the advice for reading the tenant id from HttpSession. How do I correct the order? The advice for reading the tenant id does not make any repository calls.

I tried setting the application property spring.jpa.open-in-view=false, but that didn't help.

0

There are 0 best solutions below