Spring和hibernate.cfg.xml

如何让Spring从hibernate.cfg.xml加载Hibernate的属性?

我们使用Spring和JPA(以Hibernate作为实现)。 Spring的applicationContext.xml指定了JPA方言和Hibernate属性:

       org.hibernate.dialect.MySQLInnoDBDialect    

在这个配置中,Spring通过applicationContext.xml读取所有Hibernate属性。 当我创建一个hibernate.cfg.xml (位于我的类路径的根目录,与META-INF相同的级别)时,Hibernate根本不读它(它完全被忽略)。

我想要做的是通过在hibernate.cfg.xml插入缓存属性来配置Hibernate二级缓存:

  

试试这样的事……

    classpath:location_of_config_file/hibernate.cfg.xml     ...    

之前我这样做的方法是实例化LocalSessionFactoryBean并设置configLocation属性。