如何让Spring从hibernate.cfg.xml
加载Hibernate的属性?Spring和hibernate.cfg.xml
我们使用Spring和JPA(以Hibernate作为实现)。 Spring的applicationContext.xml
指定JPA方言和Hibernate属性:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
</props>
</property>
</bean>
在这种配置中,春天的applicationContext.xml通过阅读完所有的Hibernate属性。当我创建一个hibernate.cfg.xml
(位于我的类路径的根,与META-INF相同)时,Hibernate根本不会读取它(它完全被忽略)。
我试图做的是配置Hibernate二级缓存通过插入缓存属性在hibernate.cfg.xml
:
<cache
usage="transactional|read-write|nonstrict-read-write|read-only"
region="RegionName"
include="all|non-lazy"
/>