We configure our Session Factory bean in XML. The default session name is read from a properties file that is in the resource folder of the code. For a new purpose, I need to be able to change the default schema property to something else at runtime. I cannot figure out how.
The session factory is created in the XML wiring as follows:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.default_schema">${oracle.default_schema}</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.generate_statistics">false</prop>
... other properties ...
</props>
</property>
... lots of mapping files and annotated classes ...
I thought I could pull the session factory out of Spring's context, perhaps provide a Properties class to (I hoped) override the default session property and nothing else, and then continue on my way happily.
Unfortunately, when I try to get the session factory bean out of the context, it's of type SessionFactoryImpl
and not AnnotationSessionFactoryBean
. This means the setHibernateProperties()
method is not available to me.
I'm not sure if I can call ALTER SESSION
either. Because the session factory is obtained by our DAO classes in a library, I don't have an easy way of wrapping the session factory with the necessary code.
Any ideas?