Posted in Java, Spring framework

Defining HibernateExceptionTranslator

I wanted to avoid defining any Spring bean XML configuration generally for my Spring apps. Firing up Jetty with Maven, you may sometimes encounter the following:

java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation. at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.

When defining your beans using annotations in Spring, simply specify a method annotated with @Bean that returns an instance of HibernateExceptionTranslator. The method name can be arbitrary.