Access to Session using Spring JPA and Hibernate in order to enable filters

I ended up with AOP solution : @Aspect @Component public class EnableFilterAspect { @AfterReturning( pointcut=”bean(entityManagerFactory) && execution(* createEntityManager(..))”, returning=”retVal”) public void getSessionAfter(JoinPoint joinPoint, Object retVal) { if (retVal != null && EntityManager.class.isInstance(retVal)) { Session session = ((EntityManager) retVal).unwrap(Session.class); session.enableFilter(“myFilter”).setParameter(“myParameter”, “myValue”); } } }

Spring Hibernate – Could not obtain transaction-synchronized Session for current thread

You must enable the transaction support (<tx:annotation-driven> or @EnableTransactionManagement) and declare the transactionManager and it should work through the SessionFactory. You must add @Transactional into your @Repository With @Transactional in your @Repository Spring is able to apply transactional support into your repository. Your Student class has no the @javax.persistence.* annotations how @Entity, I am assuming … Read more