-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Closed as not planned
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: enhancementA general enhancementA general enhancement
Description
If a SQLExceptionTranslator bean has been defined, it should be used in the autoconfiguration of JdbcTemplate and LocalContainerEntityManagerFactoryBean.
Otherwise, it is fiddly to guarantee that the translator has been set before the autoconfigured beans are fist used. I think this would do it, but it's going to slow down startup:
@RequiredArgsConstructor
public class SQLExceptionTranslatorBeanPostProcessor implements BeanPostProcessor {
private final SQLExceptionTranslator translator;
public @Nullable Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof AbstractEntityManagerFactoryBean emfb) {
JpaDialect dialect = emfb.getJpaVendorAdapter().getJpaDialect();
if (dialect instanceof HibernateJpaDialect hibernate) {
hibernate.setJdbcExceptionTranslator(translator);
}
} else if (bean instanceof JdbcTemplate template) {
template.setExceptionTranslator(translator);
}
return bean;
}
}Metadata
Metadata
Assignees
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: enhancementA general enhancementA general enhancement