如何让Spring从hibernate.cfg.xml加载Hibernate的属性
我们使用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>在此配置中,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"
/>发布于 2009-01-26 16:02:05
试试这样的..。
<bean
id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>
classpath:location_of_config_file/hibernate.cfg.xml
</value>
</property>
<property name="hibernateProperties">
<props>
...
</props>
</property>
</bean>发布于 2009-01-23 05:51:42
我之前的方法是实例化一个LocalSessionFactoryBean并设置configLocation属性。
https://stackoverflow.com/questions/471799
复制相似问题