title: Defining HibernateExceptionTranslator: No persistence exception translators found in bean factory
body: <p>I am trying to inject a eventRepository which is Spring Data Repository in my project:</p>
  
  <pre><code>public class App {
  
      protected static EntityManagerFactory factory;
  
      @Autowired
      protected EventRepository eventRepository;
  
      public void execute() {
          Event foo = eventRepository.findBySlug("abraxas");
      }
  
      public static void main(String[] args) {
          ApplicationContext context =
                  new ClassPathXmlApplicationContext("beans.xml");
  
          App runner = (App) context.getBean("AppBean");
          runner.execute();
      }
  }
  </code></pre>
  
  <p>beans.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:jpa="http://www.springframework.org/schema/data/jpa"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/data/jpa
              http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
      &lt;bean id="AppBean" class="org.app.App"&gt;&lt;/bean&gt;
      &lt;jpa:repositories base-package="org.app.repository" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>But when I run it I get following exception: </p>
  
  <pre>
  java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation.
  at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators
  </pre>
  
  <p>In some comments I found I need to "configure <code>HibernateExceptionTranslator</code>", but I did not manage to find out how. </p>
  
  <p>I am trying to follow the <a href="http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/" rel="nofollow">official documentation</a> which does not mention configuration of <code>HibernateExceptionTranslator</code>.</p>
  
  <p>Thanks</p>