将 PersistenceExceptionTranslationPostProcessor 与 Spring 的 JdbcTemplate 一起使用是否有意义?

wil*_*ing 5 spring hibernate jdbc spring-data spring-data-jpa

标题不言自明。

PersistenceExceptionTranslationPostProcessor 是仅用于 JPA 实现还是与 Spring 的 JdbcTemplate 一起使用也相关?

如果需要两个数据源,每个数据源都有自己的 JPA 实体管理器和事务管理器,我是否仍然只需要为整个应用程序指定一个 PersistenceExceptionTranslationPostProcessor ?

wil*_*ing 4

自动奖励赏金的答案是错误的

\n\n

~~~正确答案如下~~~

\n\n

我相信我在这里找到了答案:\n http://www.deroneriksson.com/tutorials/java/spring/introduction-to-the-spring-framework/component-scanning-and-repository

\n\n
\n

在将异常转换为基于 Spring 的未检查异常时,@Repository 注释可以发挥特殊作用。回想一下 JdbcTemplate 为我们处理了这个任务。当我们使用 Hibernate 时,我们\xe2\x80\x99 不会使用处理基于 Hibernate 的异常到基于 Spring 的异常的转换的 Spring 模板。因此,为了自动处理此转换,使用 @Repository 注释的 Hibernate DAO 将使用 PersistenceExceptionTranslationPostProcessor 将其 Hibernate 异常重新抛出为 Spring 异常。

\n
\n\n

进一步阅读:http://www.deroneriksson.com/tutorials/java/spring/introduction-to-the-spring-framework/hibernate-daos

\n\n

上面的段落明确指出: \n回想一下 JdbcTemplate 为我们处理了此任务

\n\n

因此,要回答我自己的问题,不需要将 PersistenceExceptionTranslationPostProcessor 与 jdbcTemplate 一起使用

\n