开发者

Is there any advantage to use spring DataAccessExceptions instead of JPA PersistenceExceptions?

I'm using JPA in my DAOs outside of Spring . The Spring framework defines DataAccessExceptions that are independent of databases implementations. Is there any advantage for a non Spring user to use the Spring data access exceptions instead of开发者_开发技巧 those of JPA ?

I guess that the Spring DataAccessExceptions exist since Spring handle several underlayers, (such Hibernate, Jpa, jdo, jdbc) and that the Spring Data Access Exception stack is usefull only if my application have DAOs using several technologies that have not a common standard interface (such JPA).

Am I right ?


I'd say you're pretty much there. Another advantage is that there is a family of DataAccessExceptions (CleanupFailure, SQLGrammar, etc off the top of my head), so a DAO can be programmed to explicitly catch a specific exception that you might be expecting.

But since you're usually not expecting a data access error, you usually leave it uncaught anyway, so the full purpose of the DataAccessException isn't usually needed.

(I used to be a huge fan of the DataAccessException hierarchy, but I've actually needed it so rarely that I am now happy to deal with raw JPAException).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜