E
E
EVGENY T.2019-08-13 09:42:35
Hibernate
EVGENY T., 2019-08-13 09:42:35

How to include Spring and Hibernate configuration files?

Please help me with setting up Hibernate. Here I have a spring application, there is an xml file with a context that I load at startup (there I have declared hibernate factory, datasource beans):

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

Everything is fine, but here it was necessary to enable the second-level hibernate cache using the settings:
<hibernate-configuration>
    <session-factory>
        <property name="cache.use_second_level_cache">true</property>
        <property name="cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
    </session-factory>
</hibernate-configuration>

But where to write these settings? applicationContext.xml does not accept. If placed in a separate file, then how to tell the application to use it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Osipov, 2019-08-13
@Shiftuia

If placed in a separate file, then this line should help

HibernateSessionFactory.setHibernateConfigPath("путь_к_папке_с_конфигами/hibernate.cfg.xml");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question