Announcement Announcement Module
Collapse
No announcement yet.
Spring + Plain JPA (OpenJPA) + Exception Translation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + Plain JPA (OpenJPA) + Exception Translation

    Hi All

    I'm trying to implement plain JPA in Spring as described here http://static.springframework.org/sp...rence/orm.html and in a few blogs I've been reading.

    I found http://code.google.com/p/mvn2-spring-jpa and have been adapting/improving it as I go along and learn things.

    Anyway - all was working fine until I realised the sample was not doing Exception Translation. I added the required PersistenceExceptionTranslationPostProcessor in my spring config and as soon as I added the @Repository annotation to Dao - then I get the following failure:

    Code:
    SEVERE: Caught exception while allowing TestExecutionListener
    [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1b34126]
    to prepare test instance [net.usefulbits.PersonTest@17a4989]
    org.springframework.beans.factory.BeanCreationException: Error creating
    bean with name 'net.usefulbits.PersonTest': Injection of resource methods failed;
    nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
    Bean named 'personDao' must be of type [net.usefulbits.dao.JpaPersonDao],
    but was actually of type [$Proxy16]
    Looks like the personDao is not being injected correctly - but I can't seem to work out how this is happening. Any ideas?

    My current code is all now on github on my develop branch:

    http://github.com/spidie/mvn2-spring...a/tree/develop

    this is the last bit of my sample I need to get working - then I'll merge to master and release.

    Many thanks in advance.
    Steve

  • #2
    I suggest the search function...

    Spring by default uses interface based proxying. It creates a proxy of your class which implements all the interfaces of your class. YOur testcase requires a concrete implementation instead of a interface (PersonDao). Program to interfaces not concrete implementations.

    Comment


    • #3
      Thanks Marten

      I see it now - this was carried over from the original code and it was staring me right in the face. Have changed the test to use only interfaces now and all seems to run now. Will write some tests to prove the translation works tomorrow.

      My code is here

      http://github.com/spidie/mvn2-spring-openjpa

      Hope it's of use to someone. Feel free to fork and make it better if anyone is interested in this stuff.

      Steve

      Comment

      Working...
      X