Spring的DAO框架没有抛出与特定技术相关的异常,例如SQLException或HibernateException,抛出的异常都是与特定技术无关的org.springframework.dao.DataAccessException类的子类,避免系统与某种特殊的持久层实现耦合在一起。DataAccessException是RuntimeException,是一个无须检测的异常,不要求代码去处理这类异常,遵循了Spring的一般理念:异常检测会使代码到处是不相关的catch或throws语句,使代码杂乱无章;并且NestedRuntimeException的子类,是可以通过NestedRuntimeException的getCause()方法获得导致该异常的另一个异常。Spring的异常分类有
Spring的DAO异常层次
异常
何时抛出
CleanupFailureDataAccessException 一项操作成功地执行,但在释放数据库资源时发生异常(例如,关闭一个Connection) DataAccessResourceFailureException 数据访问资源彻底失败,例如不能连接数据库 DataIntegrityViolationException Insert或Update数据时违反了完整性,例如违反了惟一性限制 DataRetrievalFailureException 某些数据不能被检测到,例如不能通过关键字找到一条记录 DeadlockLoserDataAccessException 当前的操作因为死锁而失败 IncorrectUpdateSemanticsDataAccessException Update时发生某些没有预料到的情况,例如更改超过预期的记录数。当这个异常被抛出时,执行着的事务不会被回滚 InvalidDataAccessApiusageException 一个数据访问的JAVA API没有正确使用,例如必须在执行前编译好的查询编译失败了 invalidDataAccessResourceUsageException 错误使用数据访问资源,例如用错误的SQL语法访问关系型数据库 OptimisticLockingFailureException 乐观锁的失败。这将由ORM工具或用户的DAO实现抛出 TypemismatchDataAccessException Java类型和数据类型不匹配,例如试图把String类型插入到数据库的数值型字段中 UncategorizedDataAccessException 有错误发生,但无法归类到某一更为具体的异常中 Spring的DAO异常层次是如此的细致缜密,服务对象能够精确地选择需要捕获哪些异常,捕获的异常对用户更有用的信息,哪些异常可以让她继续在调用堆栈中向上传递。
DataAccessException,它是由Spring framework定义的运行时异常。关于DataAccessException,有两件事需要注意。首先,它是运行时异常,所以使用数据访问对象的应用程序代码不需要像在JDBC和EJB 2.x实体bean的情况下那样使用try-catch块包装每次调用。第二,DataAccessException是有用的,因为它包装底层持久化技术所使用的特定异常类,从而使应用程序的其他部分独立于持久化层。
Spring’s DAO frameworks do not throw technology-specific exceptions, such
as SQLException or HibernateException. Instead, all exceptions thrown are
subclasses of the technology-agnostic org.springframework.dao.DataAccess-
Exception. This enables your data access interfaces to throw Spring’s general
DataAccessException instead of implementation-specific exceptions that would
force other application layers to catch them and thus become coupled to a particular
persistence implementation. In fact, you can intermingle multiple persistence
technologies within the same application without your service objects even
knowing it.
Since DataAccessException is the root of all Spring DAO exceptions, there are
a couple of important things to know.
Spring的DAO异常层次
异常
何时抛出
CleanupFailureDataAccessException 一项操作成功地执行,但在释放数据库资源时发生异常(例如,关闭一个Connection) DataAccessResourceFailureException 数据访问资源彻底失败,例如不能连接数据库 DataIntegrityViolationException Insert或Update数据时违反了完整性,例如违反了惟一性限制 DataRetrievalFailureException 某些数据不能被检测到,例如不能通过关键字找到一条记录 DeadlockLoserDataAccessException 当前的操作因为死锁而失败 IncorrectUpdateSemanticsDataAccessException Update时发生某些没有预料到的情况,例如更改超过预期的记录数。当这个异常被抛出时,执行着的事务不会被回滚 InvalidDataAccessApiusageException 一个数据访问的JAVA API没有正确使用,例如必须在执行前编译好的查询编译失败了 invalidDataAccessResourceUsageException 错误使用数据访问资源,例如用错误的SQL语法访问关系型数据库 OptimisticLockingFailureException 乐观锁的失败。这将由ORM工具或用户的DAO实现抛出 TypemismatchDataAccessException Java类型和数据类型不匹配,例如试图把String类型插入到数据库的数值型字段中 UncategorizedDataAccessException 有错误发生,但无法归类到某一更为具体的异常中 Spring的DAO异常层次是如此的细致缜密,服务对象能够精确地选择需要捕获哪些异常,捕获的异常对用户更有用的信息,哪些异常可以让她继续在调用堆栈中向上传递。
DataAccessException,它是由Spring framework定义的运行时异常。关于DataAccessException,有两件事需要注意。首先,它是运行时异常,所以使用数据访问对象的应用程序代码不需要像在JDBC和EJB 2.x实体bean的情况下那样使用try-catch块包装每次调用。第二,DataAccessException是有用的,因为它包装底层持久化技术所使用的特定异常类,从而使应用程序的其他部分独立于持久化层。
Spring’s DAO frameworks do not throw technology-specific exceptions, such
as SQLException or HibernateException. Instead, all exceptions thrown are
subclasses of the technology-agnostic org.springframework.dao.DataAccess-
Exception. This enables your data access interfaces to throw Spring’s general
DataAccessException instead of implementation-specific exceptions that would
force other application layers to catch them and thus become coupled to a particular
persistence implementation. In fact, you can intermingle multiple persistence
technologies within the same application without your service objects even
knowing it.
Since DataAccessException is the root of all Spring DAO exceptions, there are
a couple of important things to know.
发表评论
-
Spring MVC Controller单例陷阱
2014-09-12 10:01 927Spring MVC Controller默认是单例的: 单 ... -
Spring MVC模型(Model)层和视图(View)层
2014-04-20 18:57 0Spring MCV中Model层是View层的数据容器,Js ... -
springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
2014-04-20 18:52 3069spring mvc处理方法支持如下的返回方式:ModelAn ... -
spring mvc常用注解@Component @Controller @Service @Repository
2014-03-13 16:10 9182注解用了之后,会在*.xml文件中大大减少配置量。以前我们每个 ... -
applicationContext.xml 配置文件在web.xml中的写法
2014-03-11 16:28 2793applicationContext.xml 配置文件的一些认 ... -
SpringMVC和Struts2的比较
2014-02-27 19:12 748通俗说Spring的作用 Spring ... -
Struts-config.xml配置文件《action-mappings》元素的详解
2014-02-26 13:12 2448action-mappings 该元素用于将Action元素定 ... -
使用Hibernate向mysql数据库中插入中文,数据库中显示??乱码
2014-02-24 23:02 1015[size=medium]通过网上学习,要求修改Hiberna ... -
在web.xml中通过contextConfigLocation配置spring
2014-02-24 21:19 2318在web.xml中通过contextConfigLocatio ... -
Struts-config.xml配置action-mappings元素略计
2014-02-24 16:58 636action-mappings 该元素用于将Action元素 ... -
Result Type(Struts.xml配置)
2013-06-25 08:35 624一个提交到服务器的处理通常可以分为两个阶段: 第一个阶段查询服 ... -
ibatis常用标记略记
2013-06-23 21:12 972isNull判断property字段是否是null,用isEm ... -
ibatis的iterate使用
2013-06-23 20:38 1088ibatis的iterate使用 Iterate:这属性遍历 ... -
Struts2 两个Action之间动态传参
2013-06-21 10:00 1049两个Action 动态传参数 研究了近两天的时间 ... -
spring入门之—第一步
2013-06-13 15:26 723注: 本文用的是spring-framework-3.1.1. ... -
Spring的ApplicationContext加载多个配置文件的三种方式
2013-06-13 15:09 18301.第一种,使用数组方式 ApplicationConte ... -
详解iBaits中SqlMapClientTemplate的使用
2013-06-05 16:07 0pache iBatis(现已迁至Google Code下发展 ... -
Struts2.0默认支持多种格式的result type
2013-06-05 16:00 859<action name="attachmen ... -
maven+ssi对oracle实现增删改查(二)
2013-06-05 12:06 12001.index.jsp访问项目默认页面 <%@ page ... -
maven+ssi对oracle实现增删改查(一)
2013-06-05 11:40 1231-. 1.Oracle10g 的表结构语句,需要内容的自己添加 ...
相关推荐
Spring的DataAccessException
MyBatis-Spring连接类。... 而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。
MyBatis-Spring 会帮助你... 而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。
而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。 正如第二版那样,Spring ...
MyBatis-Spring 会帮助你... 而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。
MyBatis-Spring 会帮助你... 而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。
MyBatis-Spring 会帮助你... 而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。
The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced异常缺少的包
4.1.1 理解Spring的DataAccessException 4.1.2 与DataSource一起工作 4.1.3 一致的DAO支持 4.2 在Spring中使用JDBC 4.2.1 JDBC代码的问题 4.2.2 使用JdbcTemplate 4.2.3 把操作创建成...
它将允许 MyBatis 参与到 Spring 的事务管理之中,创建映射器 mapper 和 SqlSession 并注入到 bean 中,以及将 Mybatis 的异常转换为 Spring 的 DataAccessException。最终,可以做到应用代码不依赖于 MyBatis,...
The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files 解决方法: 导入spring-tx-4.2.2.RELEASE.jar包。
不再强制开发者在持久层捕捉异常,持久层异常被包装成DataAccessException,底层数据库异常包装成业务异常。开发者可以自己决定在合适的层处理。 HibernateTemplate支持类。可以完成大量Hibernate持久层的操作。 ...
MyBatis ORM框架 ... 而且它也会处理事务, 翻译 MyBatis 的异常到 Spring 的 DataAccessException 异常(数据访问异常,译者注)中。最终,它并 不会依赖于 MyBatis,Spring 或 MyBatis-Spring 来构建应用程序代码。
All Classes ...DataAccessException DataAccessResourceFailureException DataAccessUtils Database DatabaseMetaDataCallback DatabaseStartupValidator DataBinder DataFieldMaxValueIncrementer ...
doma-spring-boot Spring Boot支持属性文件配置doma.dialect = # Dialect of database used by Doma. (STANDARD, SQLITE, DB2, MSSQL, MYSQL, POSTGRES, ORACLE, H2, HSQL)doma.sql-file-repository = # Type of ...
public List<Attendance> findAttsBetweenDates(int attendanceState,Date fromTime,Date toTime)throws DataAccessException; /**保存考勤信息 * @param att 考勤信息 * @throws DataAccessException */ ...
import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.RowMapper; import entity.Material; public class MaterialService extends BaseService { /** * 把...
DataAccessException 500 数据访问错误 1.1.3 Servlet异常处理器 负责处理Servlet产生的异常: 异常类型 响应码 响应文本 DataAccessException 500 数据访问错误 NoHandlerFoundException 404 没有对应的处理器 ...
(3) com.chen.exception.DataAccessException.java 是一个自定义异常,用于用户登入时判断用户名及密码. (4)com.chen.web.interceptor.AuthorizationInterceptor.java 限制上传大小的拦截器 (5) src下的...
进口摆渡.eto.DataAccessException; 进口ferry.eto.NoSuchFerryException; 进口ferry.eto.NoSuchHarbourException; 进口ferry.eto.NoSuchRouteException; 进口ferry.eto.NoSuchScheduleException; 进口ferry.eto....