【发布时间】:2010-10-03 01:49:43
【问题描述】:
如何让 Spring 从 hibernate.cfg.xml 加载 Hibernate 的属性?
我们使用 Spring 和 JPA(使用 Hibernate 作为实现)。 Spring 的 applicationContext.xml 指定了 JPA dialect 和 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>
在这个配置中,Spring 通过 applicationContext.xml 读取所有的 Hibernate 属性。当我创建一个hibernate.cfg.xml(位于我的类路径的根目录,与 META-INF 相同的级别)时,Hibernate 根本不读取它(它完全被忽略了)。
我要做的是通过在hibernate.cfg.xml 中插入缓存属性来配置 Hibernate 二级缓存:
<cache
usage="transactional|read-write|nonstrict-read-write|read-only"
region="RegionName"
include="all|non-lazy"
/>
【问题讨论】: