Announcement Announcement Module
No announcement yet.
Spring + Plain JPA (OpenJPA) + Exception Translation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 and in a few blogs I've been reading.

    I found 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:

    SEVERE: Caught exception while allowing TestExecutionListener
    [org.springframewor[email protected]1b34126]
    to prepare test instance [[email protected]]
    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:

    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.

  • #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.


    • #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

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