I would like to know if it is possible to intercept the Hibernate Session creation, to automatically enable a filter when the transaction starts. I can do this if and only if spring Boot uses a dedicated session for each http request: my second question.
I have a Service class with a method marked as @Transactional
.
@Service
public class MyServiceImpl implements MyService {
@Override
@Transactional
public void saveEntity(Entity entity) {
//save entity
}
}
I have a RestController class that exposes an endpoint and it uses the service class.
@RestController
@RequestMapping("/service")
public class MyRestController {
private final MyService myService;
@GetMapping("save")
public String save() {
myService.saveEntity(entity);
}
}
- Does Spring Boot create a new dedicated hibernate session for the http request?
- If yes, is it possible to intercept (via callback for example) the session creation to enable an hibernate filter?