Announcement Announcement Module
Collapse
No announcement yet.
Test with JUnit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Test with JUnit

    Hi,

    I'm trying to execute a JUnit Test in my daos, but throws an LazyInitializationException. I think that is because when i load an object from database, the session is closed. The method i'm trying to test an update method, where i have to load an object from database, modify it, then call update method.



    how can i keep the session opened in my test?

    Hibernate: 3.0.5
    Spring: 1.2.3

  • #2
    Check out chapter 22 of the Spring reference manual for information on our transactional test classes that can help solve this problem.

    Rob

    Comment


    • #3
      You might find this link useful also: http://www.jroller.com/page/kbaum/Weblog?catname=/Java

      Look for the heading Being Lazy in your Unit Tests. NB you can remove the getBean methods and use the autowiring which is in the Spring reference manual as robh has shown above.

      Comment


      • #4
        Problem solved.

        I create a test class that extends AbstractTransactionalSpringContextTests
        Create a method called getConfigLocations():
        Run the JUnitTest.

        thanks

        Comment

        Working...
        X