Spring boot app, need to set a database session variable before every transaction2020-04-01 spring hibernate spring-boot jpa
I have a spring boot application that uses Hibernate/JPA entities. I need to run a bit of SQL to set a database session variable prior to each transaction. This session variable controls row level security at the database layer and so the SQL will use a web session parameter which I can retrieve from the spring web session context. I will need this bit of sql to run essentially before every transaction.
I'd like to be able to do this in a way that does not effect every additional piece of business logic. i.e. I'd rather not have to call the method manually from every repository class.
I saw the ConnectionPreparer class in the spring-data-jdbc-ext project (https://github.com/spring-projects/spring-data-jdbc-ext/blob/master/spring-data-jdbc-core/src/main/java/org/springframework/data/jdbc/support/ConnectionPreparer.java). However it appears this class is only called when the connection is first instantiated, not prior to every transaction.
- What's the difference between JPA and Spring Data JPA?
- Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed
- Spring Boot & Spring Data: how are Hibernate Sessions managed?
- Spring Boot 2.0.4 and WAS Liberty transaction 220.127.116.11 Transaction manager issue
- Avoiding "set session transaction read" in spring boot application with mysql
- How to use Spring Boot with MySQL database and JPA?
- Spring Boot JPA with not a well known database
- Spring @Transactional(Propagation.NEVER) should create hibernate session?