首先要在spring.xml里面配置sessionfactory和其他的,sessionfactory里面要制定hbm.xml文件的位置
Java代码:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<!-- 表示允许自动提交 -->
<prop key="hibernate.connection.autocommit">true</prop>
<!-- 显示sql语句 -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- 自动生成表结构
<prop key="hibernate.hbm2ddl.auto">create</prop>
-->
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/hibernate</value>
</list>
</property>
</bean>
Java代码:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<!-- 表示允许自动提交 -->
<prop key="hibernate.connection.autocommit">true</prop>
<!-- 显示sql语句 -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- 自动生成表结构
<prop key="hibernate.hbm2ddl.auto">create</prop>
-->
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/hibernate</value>
</list>
</property>
</bean>
Spring与Hibernate整合配置
本文详细介绍了如何在Spring框架中配置Hibernate,实现数据库操作。通过配置sessionFactory组件,指定数据源、Hibernate属性如dialect、自动提交等,并设置Hibernate映射文件的位置。
4860

被折叠的 条评论
为什么被折叠?



