Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Documentation : first example does not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Documentation : first example does not work

    Hello all!

    I'm trying to use Spring data with JPA, but nothing works, I always get this exception : org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation.

    I have created a new Spring MVC project from template, and i have updated the pom with these :

    Code:
    <repository>
     <id>spring-milestone</id>
     <name>Spring Maven MILESTONE Repository</name>
     <url>http://repo.springsource.org/libs-milestone</url>
    </repository>
    and

    Code:
    <dependency>
     <groupId>org.springframework.data</groupId>
     <artifactId>spring-data-jpa</artifactId>
     <version>1.0.3.RELEASE</version>
    </dependency>
    I have replaced the contents of the servlet-context.xml by the (corrected) XML given in the documentation : http://static.springsource.org/sprin....query-methods

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.springframework.org/schema/data/jpa"
      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">
    
      <repositories base-package="com.acme.repositories" />
    
    </beans:beans>
    And when I run the app on Tomcat I get the exception!

    It seems that this is related to a bean of this class : "org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor"

    Actually, even with this XML configuration the application won't work, with exactly the same exception thrown :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.springframework.org/schema/data/jpa"
      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">
    
      <beans:bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    
    </beans:beans>
    I did some searches, but it lead to nothing, as nobody posted a solution on the other threads I found.

    I would be grateful if somebody can tell me what's wrong with the XML context files I am using, because this is only the first example in the JPA documentation.

    Best regards,

  • #2
    I suggest a read of the spring (not spring data!) reference guide.

    What does the stacktrace tell you

    Code:
    rg.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation.
    The PersistenceExceptionTranslationPostProcessor cannot find a bean which is able to translate the exceptions. No matter if you add this bean yourself or have it created by the namespaces. Nowhere in your configuration I see a EntityManagerFactoryBean or something else that configures the EntityManager.

    Spring Data JPA still needs an EntityManagerFactory and this is something I see nowhere in your configuration.

    Comment


    • #3
      Thanks a lot Marten, I made the mistake of thinking I could instantiate beans of these classes without EntityManagerFactory!

      Comment

      Working...
      X