I am using Springboot 2 with hibernate and spring data JPA.
Previously we were using the JDBC template and there we are adding schema name into SQL query based on logged-in user. like -
String sql = "Select * from " + scheama + ".table"
Now we need a similar kind of support in hibernate.
I found a couple of similar question on stack overflow like -
- Change database schema during runtime based on logged in user
- Spring JPA: Providing Schema Name Dynamically
We have schema per user and also have some shared schema that does not depends on the logged-in user. In the above example I can handle schema for the logged-in users but is there any way to handle both user schema and shared schema.
Code sample to get schema -
String sceama = this.companyService.getScheama(this.getUserCompany(request.getHeader("selectedCompany")));