Results 1 to 3 of 3

Thread: Spring + Plain JPA (OpenJPA) + Exception Translation

  1. #1
    Join Date
    Sep 2007
    Location
    Gold Coast, Australia
    Posts
    9

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2007
    Location
    Gold Coast, Australia
    Posts
    9

    Default

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •