什么是“持久性异常翻译"?用于@Repository bean [英] What is "persistence exception translation" for @Repository beans

查看:137
本文介绍了什么是“持久性异常翻译"?用于@Repository bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读带有注释部分的Spring,并且遇到了@Repository annotation
我读到@Repository bean与@Component bean有所不同,因为它们符合持久性异常转换的条件.

I was reading Spring with annotation part and I came across @Repositoryannotation
I read that @Repository beans differ from @Component beans in the sense that they are eligible for persistence exception translation.

有人可以详细说明持久性异常翻译的含义吗?

Can somebody please elaborate what is meant by persistence exception translation?

推荐答案

持久性异常转换是将低级持久性异常转换为高级Spring异常的过程.

Persistence Exception Translation is the process of converting low level persistence exceptions into high level Spring exceptions.

从SpringSource站点:

From the SpringSource Site:

常见数据访问异常. Spring可以包装来自您的异常 首选的O/R映射工具,可将它们从专有的转换 (可能检查的)公共运行时异常 DataAccessException层次结构.这使您能够处理大多数 持久性异常,这是不可恢复的,仅在 适当的层,而不会令人讨厌的样板捕获/抛出,以及 异常声明.您仍然可以捕获和处理异常 您需要的任何地方.请记住,JDBC异常(包括数据库) 特定的方言)也将转换为相同的层次结构,这意味着 您可以在一个一致的范围内使用JDBC执行某些操作 编程模型.

Common data access exceptions. Spring can wrap exceptions from your O/R mapping tool of choice, converting them from proprietary (potentially checked) exceptions to a common runtime DataAccessException hierarchy. This allows you to handle most persistence exceptions, which are non-recoverable, only in the appropriate layers, without annoying boilerplate catches/throws, and exception declarations. You can still trap and handle exceptions anywhere you need to. Remember that JDBC exceptions (including DB specific dialects) are also converted to the same hierarchy, meaning that you can perform some operations with JDBC within a consistent programming model.

这样做的主要好处之一是将异常转换为运行时异常,实际上,不需要将throws声明添加到方法签名中.

One of the major benefits of this is that exceptions are turned into Runtime Exceptions, in effect you are not required to add the throws declaration to your methods signature.

http://static.springsource.org/spring/docs/2.5.x/reference/orm.html

这篇关于什么是“持久性异常翻译"?用于@Repository bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆