如何讓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"
/>