We want to use Spring in combination with Hibernate and to utilize all the Hibernate support features of Spring (declarative transaction management, etc.).
So we have the usual setup for a web application with Spring and Hibernate:
- - Datasource definition
- SessionFactory definition with injected Datasource reference
- some Hibernate mappings
- declarative TX proxy with reference to SessionFactory
Nothing unusual here and everything works as expected.
But now we have the requirement that we need to expand/modify the Hibernate mappings during runtime. The administrator of the application can add columns to some tables and these columns should be mapped to a Hibernate "dynamic component".
Starting with the next request after the reconfiguration all requests should use the "new" mapping.
But the Hibernate SessionFactory is immutable. So you need to create a new SessionFactory with a modified mapping.
It would be easy to solve this with a kind of "restart".
Shutting down the spring container and starting again with a modied configuration. But this has the drawback that you must stop/wait for all running requests.
So what we want to achieve is something like the following:
Has anyone solved this or has an idea how to solve this?
mapping 1 -> SessionFactory1 (SF1)
request1/thread 1 starts, uses SF1
request2/thread 2 starts, uses SF1
-- modification of mapping
mapping 2 -> SessionFactory2 (SF2)
all requests, which have started before, continue to use SF1
new requests use SF2
when all "old" requests have ended SF1 could be garbage collected