关于spring事务异常捕获! DataAccessException 和 Exception 的疑问

dojax 2008-01-18 04:03:55
try
{
this.getOcsServices().del(p);
} catch (DataAccessException e)
{
XXXXXX
} catch(Exception e)
{
XXXXX
}
我在web层执行上述代码,系统是spring+hibernate结构 this.getOcsServices().del(p);为调用service层的事务,按spring文档的说法一般所有异常都会自动包装到DataAccessException 中,但是我却发现了一条SQLException异常却不在DataAccessException 中,需要我用catch(Exception e)才能捕获到。
不知各位大虾是否有相关的知识或者经验? 望分享之,谢谢
...全文
2755 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
printfabcd 2010-04-09
  • 打赏
  • 举报
回复
我想可能是因为,DataAccessException是运行时异常,是一个RuntimeException,所以可能他不会管,非运行时异常O(∩_∩)O~
yanransoft 2008-04-08
  • 打赏
  • 举报
回复
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.
yanransoft 2008-04-08
  • 打赏
  • 举报
回复
同样问此问题,顶一下~
dojax 2008-01-21
  • 打赏
  • 举报
回复
e: java.lang.Exception = {org.hibernate.exception.GenericJDBCException@b9d}
cause: java.lang.Throwable = {java.sql.SQLException@ba2}
delegate: org.hibernate.exception.NestableDelegate = {org.hibernate.exception.NestableDelegate@ba3}
detailMessage: java.lang.String = "could not execute update query"
sqle: java.sql.SQLException = {java.sql.SQLException@ba2}
SQLState: java.lang.String = "JZ0SJ"
cause: java.lang.Throwable = {java.sql.SQLException@ba2}
detailMessage: java.lang.String = "JZ0SJ: 没有在此数据库中发现元数据存取器信息。 请按 jConnect 文档中所述安装 所需的表。"


上面这是JBuilder的关于这个不被DataAccessException包装的异常信息, 就是很奇怪这个jdbc异常为什么不会被DataAccessException包装起来。
老紫竹 2008-01-18
  • 打赏
  • 举报
回复
什么异常呢?DataAccessException抓不住地。贴出来参考一下!

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧