Announcement Announcement Module
Collapse
No announcement yet.
Spring 3: Why is AbstractJpaTests deprecated? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment


      • #4
        I haven't had any issues, I suggest simply try it...

        Comment


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

          Comment


          • #6
            duplicate post deleted

            Comment

            Working...
            X