Results 1 to 4 of 4

Thread: Test with JUnit

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    8

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

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

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    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.

  4. #4
    Join Date
    Aug 2005
    Posts
    8

    Default

    Problem solved.

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

    thanks

Similar Threads

  1. Replies: 32
    Last Post: Feb 2nd, 2010, 12:20 PM
  2. How can I test authorization in Junit?
    By j2emmy in forum Security
    Replies: 16
    Last Post: Mar 21st, 2006, 05:23 PM
  3. ApplicationContext returns null in Junit Test Case
    By penku in forum Spring-Modules
    Replies: 2
    Last Post: Sep 17th, 2005, 01:28 PM
  4. Junit test failure
    By mhazer in forum Data
    Replies: 1
    Last Post: May 2nd, 2005, 02:37 AM
  5. Junit Test in IntelliJ
    By nisha in forum Web
    Replies: 1
    Last Post: Apr 9th, 2005, 08:44 AM

Posting Permissions

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