1. Spring 整合 Hibernate 整合什么 ?
1). 有 IOC 容器来管理 Hibernate 的 SessionFactory
2). 让 Hibernate 使用上 Spring 的声明式事务
2. 整合步骤:
1). 加入 hibernate
①. jar 包
②. 添加 hibernate 的配置文件: hibernate.cfg.xml
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!——打印sql语句——>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!--自动建表语句-->
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="javax.persistence.validation.mode">none</property>
</session-factory>
③. 编写了持久化类对应的 .hbm.xml 文件。
每一个数据库表对应一个class,每一个class文件对应一个.hbm.xml文件
文件内容如下:
<!--对应着数据库表的四个字段,其中id是主键-->
<hibernate-mapping>
<class name="com.zou.st.Account" table="SH_ACCOUNT">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="native" />
</id>
<property name="username" type="java.lang.String">
<column name="USERNAME" />
</property>
<property name="balance" type="int">
<column name="BALANCE" />
</property>
</class>
</hibernate-mapping>
2). 加入 Spring
①. jar 包
@.配置数据库连接文件
db.properties
jdbc.user=root
jdbc.password=zouhuiying
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://192.168.139.215:3306/hibernate
jdbc.initPoolSize=5
jdbc.maxPoolSize=10
②. 加入 Spring 的配置文件
applicationCintext.xml
导入源文件<context:property-placeholder location="classpath:db.properties"/>
设置基础包路径<context:component-scan base-package="com.zou"></context:component-scan>
设置dataSource属性
设置sessionFactory
3). 整合.
3. 编写代码
分享到:
相关推荐
springmvc spring hibernate整合Demo 包含了CRUD 帮助初学者快速学习springmvc
Struts2 Spring Hibernate IBatis Struts2 Spring Hibernate IBatisStruts2 Spring Hibernate IBatisStruts2 Spring Hibernate IBatis 只需要导入相应的jar包就行了 ,数据库是mysql :数据库名叫做mydatabase,表名...
struts2 spring hibernate框架技术与项目实战 光盘源码 上 资源150M必须分成3部分上中下
struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页
由于此项目中的jar包不全所以在此补全了webwork spring hibernate整合实例源代码,向大家道歉!
Struts Hibernate Spring Ajax Struts Hibernate Spring Ajax
struts2 spring hibernate框架技术与项目实战 光盘源码 中 资源150M必须分成3部分上中下
基于struts spring hibernate的航空票务系统 包含sql
Spring+Hibernate 使用TransactionInterceptor声明式事务配置
详细讲解了S2SH框架技术的基本知识和使用方法,从Eclipse开发平台、JSP、Servlet等基础知识讲起,由浅入深,重点介绍了当前流行的三个轻量级开源框架:Struts2、Spring和Hibemate.
Struts Spring Hibernate整合实践
spring hibernate ext项目
开发基于Struts Spring Hibernate Ajax的网上信息发布平台(Struts Hibernate Spring Ajax)--Chapter1
spring hibernate security整合
两个项目,一个项目是基于spring jdbc实现的分布式事务,一个是基于spring hibernate的分布式事务,hibernate项目里的applicationContext2.xml是基于mysql和mssql, applicationContext3.xml基于两个mssql, ...
开发基于Struts Spring Hibernate Ajax开发基于Struts Spring Hibernate Ajax
使用mysql数据库的struts2 spring hibernate整合简单示例,也可参考我的:“struts2 spring hibernate整合要点、注意点”这篇文档来配置
struts2 spring hibernate 整合
java javaee struts2 spring hibernate免费学习视频教程
struts spring hibernate 面试总结