Results 1 to 6 of 6

Thread: Spring 3: Why is AbstractJpaTests deprecated?

  1. #1
    Join Date
    Jul 2008
    Posts
    4

    Default Spring 3: Why is AbstractJpaTests deprecated?

    I'm a confused about the AbstractJpaTests class and why it has been marked as deprecated in Spring 3.

    The apidocs say one should use "the listener-based test context framework (AbstractJUnit38SpringContextTests)".

    How can I write JPA integration tests and how do I get the Entity Manager? I read in the documentation that since Spring 3 one can use @PersistenceUnit directly in the tests.

    What about this classloader issues that are addresses win AbstractJpaTests with the shadowing class loader, are they solved in Spring 3 or even Spring 2.5 at all?

    Hope someone can explain to me how to write transactional JPA tests without using AbstractJpaTests.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Because that whole hierarchy is deprecated.

    How to write it, well follow the instructions..

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @Transactional
    public class YourTestClass {
    
      @Autowired (or @PersistenceUnit)
      private EntityManager entityManager;
    
      public void yourTestMethod() {
        //do your tests
      }
    
    }
    For more info I suggest the test chapter.
    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
    Jul 2008
    Posts
    4

    Default

    Thanks, that looks easy!

    So there are no pitfalls with JPA and testing any more, since AbstractJpaTests uses a shadowing class loader and does some extended magic? Has this been only a problem in Spring 2.0?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I haven't had any issues, I suggest simply try it...
    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

  5. #5
    Join Date
    Apr 2008
    Posts
    7

    Default

    I have tried this but indeed I get the error "Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent" since there is no base class which is injecting a shadowing load time weaver. This weaver does not appear to be advertised as a standalone class...so is there any way to replicate the AbstractJpaTests behavior w/ JUnit4 and TestContext?

  6. #6
    Join Date
    Apr 2008
    Posts
    7

    Default

    duplicate post deleted

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
  •