<span style="font-size:14px;"><!-- 1. 创建SessionFactory -->
<!-- 【【1.1 直接加载hibernate.cfg.xml配置文件; 没有用连接池技术!】】
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
-->
<!-- 【【1.2 使用连接池管理连接; 】】
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<property name="dataSource" ref="dataSource"></property>
</bean>
-->
<!-- 【【1.3 完全在spring中,管理hibernate基本配置、映射信息; 不用加载hibernate.cfg.xml主配置文件】】 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop> 【key为hibernate的属性名称,必须要有hibernate前缀】
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!--加载映射文件的两种方式:-->
<!-- 一:加载映射文件的地址
<property name="mappingLocations">
<list>
<value>classpath:my/test/entity/*.hbm.xml</value>
</list>
</property>
-->
<!-- 二:加载映射文件所在的目录 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:my/test/entity</value>
</list>
</property>
</bean></span>
Spring对SessionFactory管理的几种方式
最新推荐文章于 2024-01-31 01:25:54 发布