[size=medium]spring与hibernate整合配置非常灵活:
1、在applicationContext.xml中引入hibernate.cfg.xml,如下:[/size]
[size=medium]2、将hibernate相关配置配在applicationContext.xml中[/size]
1、在applicationContext.xml中引入hibernate.cfg.xml,如下:[/size]
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 使用hibernate自身的配置文件配置
<property name="configLocations">
<list>
<value>classpath:cn/itcast/spring/hibernate/hibernate.cfg.xml</value>
</list>
</property>
</bean>
[size=medium]2、将hibernate相关配置配在applicationContext.xml中[/size]
<!-- 本地会话工厂bean,spring整合hibernate的核心接口 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 指定hibernate自身的属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
<!-- 从指定目录下查找映射文件-->
<property name="mappingDirectoryLocations">
<list>
<value>cn/itcast/spring/domain</value>
</list>
</property>
<!-- 映射文件的位置
<property name="mappingResources">
<list>
<value>cn/itcast/spring/domain/Customer.hbm.xml</value>
</list>
</property>
-->
</bean>