Spring学习笔记之整合hibernate
1、web.xml里边要配置好对应的springxml的路径
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
conf/kernel/spring_kernel/spring-*.xml,
conf/business/spring_business/spring-*.xml,
conf/custom/spring_custom/spring-*.xml
</param-value>
</context-param>
2、对应的文件夹里边要有spring-hibernate.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"></bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<bean class="com.**********.DataSourceFactoryBean">
<property name="propertyPool" value="**************" />
<property name="propertyPrefix" value="***************." />
</bean>
</property>
</bean>
<!-- Session工厂 - start -->
<bean id="sessionFactory" class="com.**********.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath*:conf/kernel/hibernate_kernel/**/*.hbm.xml</value>
<value>classpath*:conf/business/hibernate_business/**/*.hbm.xml</value>
<value>classpath*:conf/custom/hibernate_custom/**/*.hbm.xml</value>
</list>
</property>
<property name="lobHandler" ref="defaultLobHandler"></property>
</bean>
<!-- 声明spring事务管理 - start -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- spring_JDBC - start -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!-- spring事务传播机制 - start -->
<bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="proxyTargetClass">
<value>true</value><!-- 指定直接对类进行代理,将属性proxyTargetClass指定为true(默认是false,对接口进行代理) -->
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="inquery*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="inquiry*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="validate*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="remove*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="save*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="add*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="process*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="insert*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="create*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="update*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="modify*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="persist*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="driven*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="parse*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="middleUpdate*">PROPAGATION_REQUIRES_NEW,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
<prop key="*">PROPAGATION_REQUIRED,-java.lang.Exception,-org.springframework.dao.DataAccessException</prop>
</props>
</property>
</bean>
<bean id="dynamicBeanReader" class="com.***********.DynamicBeanReader" init-method="init">
</bean>
</beans>
3、
LOB(large object)是一种用于存储大对象的数据类型,如医学记录(如X-射线)、视频、图像等。LOB有三种类型:BLOB:Binary Large Object、CLOB:Character Large Object、DBCLOB:Double-byte Character Large Object。每个LOB可以有2GB。
4、DynamicBeanReader:bean动态加载接口.应用于运行过程中动态加载bean,比如数据源的动态加载、定时任务的动态加载等。
5、大部分情况下,每个事务代理的事务属性大同小异,事务代理的实现类都是TransactionProxyFactoryBean,事务代理bean都必须注入事务管理器。对于这种情况,Spring提供了bean与bean之间的继承,可以简化配置。将大部分的通用配置,配置成事务模板,而实际的事务代理bean,则继承事务模板。这种配置方式可以减少部分配置代码,相比前面直接采用TransactionProxyFactoryBean的事务代理配置方式,可以大大减少配置文件的代码量。每个事务代理的配置都继承事务模板,无需重复指定事务代理的实现类,无需重复指定事务传播属性——当然,如果新的事务代理有额外的事务属性,也可指定自己的事务属性,此时,子bean的属性覆盖父bean的属性。当然每个事务代理bean都必须配置自己的目标bean,这不可避免。上面的配置可看出,事务代理的配置依然是增量式的,每个事务代理都需要单独配置——虽然增量已经减少,但每个事务代理都需要单独配置。
上面spring配置中的<prop>内的值为事务属性信息,匹配格式为:PROPAGATION (传播行为) , ISOLATION (隔离级别(可选)) , readOnly (是否为只读事务(可选)) , -Exceptions (发生这些异常时回滚事务(可选)) , +Exceptions (发生这些异常时照样提交事务(可选))
6、spring默认的使用的是c3p0
Spring学习笔记之整合hibernate的更多相关文章
- Spring 学习笔记之整合Hibernate
Spring和Hibernate处于不同的层次,Spring关心的是业务逻辑之间的组合关系,Spring提供了对他们的强大的管理能力, 而Hibernate完成了OR的映射,使开发人员不用再去关心SQ ...
- Spring学习笔记四 整合SSH
三大框架架构(整合原理) 步骤1:导包 Hibernate包 1.Hibernate包,hibernate/lib/required 2.hibernate/lib/jpa | java persis ...
- Spring学习笔记之整合struts
1.现有项目是通过 <action path="/aaaaAction" type="org.springframework.w ...
- Spring MVC 学习笔记12 —— SpringMVC+Hibernate开发(1)依赖包搭建
Spring MVC 学习笔记12 -- SpringMVC+Hibernate开发(1)依赖包搭建 用Hibernate帮助建立SpringMVC与数据库之间的联系,通过配置DAO层,Service ...
- Spring学习笔记(六)—— SSH整合
一.整合原理 二.整合步骤 2.1 导包 [hibernate] hibernate/lib/required hibernate/lib/jpa 数据库驱动 [struts2] struts-bla ...
- Spring Boot 学习笔记(六) 整合 RESTful 参数传递
Spring Boot 学习笔记 源码地址 Spring Boot 学习笔记(一) hello world Spring Boot 学习笔记(二) 整合 log4j2 Spring Boot 学习笔记 ...
- Java架构师之路 Spring学习笔记(一) Spring介绍
前言 这是一篇原创的Spring学习笔记.主要记录我学习Spring4.0的过程.本人有四年的Java Web开发经验,最近在面试中遇到面试官总会问一些简单但我不会的Java问题,让我觉得有必要重新审 ...
- Spring学习笔记(一)
Spring学习笔记(一) 这是一个沉淀的过程,大概第一次接触Spring是在去年的这个时候,当初在实训,初次接触Java web,直接学习SSM框架(当是Servlet都没有学),于是,养成了一个很 ...
- Spring学习笔记2——表单数据验证、文件上传
在上一章节Spring学习笔记1——IOC: 尽量使用注解以及java代码中,已经搭建了项目的整体框架,介绍了IOC以及mybatis.第二节主要介绍SpringMVC中的表单数据验证以及文件上传. ...
随机推荐
- [js] 非常好的面试题,学习了。。
原文链接:http://www.cnblogs.com/xxcanghai/p/5189353.html
- OpenGL的glViewPort窗口设置函数实现分屏
之前实现过全景图片查看(OpenGL的几何变换3之内观察全景图),那么我们需要进行分屏该如何实现呢?如下图: 没错就是以前提过的glViewPort函数,废话不多说了,我直接上代码: //从这里开始进 ...
- shell脚本基础知识
虽然现在能在Linux系统下生存,但是自觉效率太低,和高手有很大的差距. 这就是关于Linux的知识太过匮乏,有很多事情知道该怎么做,但是就是没法在Linux下实现,为了提升工作效率,必须要接触Lin ...
- Selenium解决页面元素不在视野范围内的问题
当需要使用滚动条才能使页面元素显示在视野范围内时,必须用代码处理下,才能对其进行操作. 处理其实也很简单,就是调用JS函数. driver.executeScript("arguments[ ...
- 关于MySQL大牛周振兴的博客
博客内容比较丰富 MySQL管理 数据恢复 linux TCP 个人生活感触 不过内容总体是笔记式的,更适合自己看,不适合初学者去follow.不过对MySQL比较熟悉的人,可以看看,作为扩展眼界的途 ...
- Compound Interest Calculator4.0
Compound Interest Calculator4.0 1.团队协作准备:每个同学在github上完成FORK,COMMENT(学号后三位+姓名),PR,MERGE的过程. 2.你的RP由你的 ...
- Junit4入门
eclipse自带junit包,可右键直接新建junit类 静态引入:import static org.junit.Assert.* assert.*是类,静态引入会引入assert里的所有静态方法 ...
- JAVA 数组作业——动手动脑以及课后实验性问题
JAVA课后作业——动手动脑 一:阅读并运行示例PassArray.java,观察并分析程序输出的结果,小结,然后与下页幻灯片所讲的内容进行对照. 1.源代码 // PassArray.java // ...
- hashtable 实现
#include <stdlib.h> #include <stdio.h> #include <string.h> typedef struct _hashnod ...
- 2016年31款轻量高效的开源JavaScript插件和库
目前有很多网站设计师和开发者喜欢使用由JavaScript开发的插件和库,但同时面临一个苦恼的问题:它们中的大多数实在是太累赘而且常常降低网站的性能.其实,其中也有不少轻量级的插件和库,它们不仅轻巧有 ...