Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 40

Thread: Spring+Hibernate: connection not closed

  1. #21
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Ok, and which line is this: com.test.service.TestServiceBean.testOnDBError(Tes tServiceBean.java:4
    2)

  2. #22
    Join Date
    Dec 2006
    Posts
    23

    Default

    Code:
    	public void testOnDBError(){
    			this.impl.testOnDBError();
    	}

    and the impl is:
    Code:
    	public void testOnDBError() {
    		System.out.println("getPOJO");
    		POJO p = this.dao.getPOJO();
    		System.out.println("setDateDerniereModification");
    		p.setDateDerniereModification(new Date());
    		// on fait planter au commit
    		System.out.println("setValeurNonNullable");
    		p.setValeurNonNullable(null);
    	}
    Last edited by david.chau; Jan 31st, 2007 at 04:17 AM. Reason: add impl

  3. #23
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    If

    this.impl.testOnDBError();

    is line 42 then impl is for some reason null, has nothing to do with database.

  4. #24
    Join Date
    Dec 2006
    Posts
    23

    Default

    OK SORRY my fault (I am not awake yet...)
    Here is the log.
    I apologize for the mistake
    Attached Files Attached Files

  5. #25
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    The exception here, is one of lazy initialization as the session has closed. This was a change from Hibernate 2 to 3 as the default behaviour. This has nothing to do with Spring.

    Since it is best practice to map almost all classes and collections using lazy="true", that is now the default. Existing applications will need to explicitly specify lazy="false" on all non-lazy class and collection mappings.
    http://www.hibernate.org/250.html

    Solutions to this in unit tests are discussed here.
    http://forum.springframework.org/showthread.php?t=9630
    http://forum.hibernate.org/viewtopic.php?t=929167
    http://www.springframework.org/docs/...tml#testing-tx
    Last edited by karldmoore; Jan 31st, 2007 at 04:54 AM.

  6. #26
    Join Date
    Dec 2006
    Posts
    23

    Default

    I put lazy="false".
    It seems that the RuntimeException is not thrown...
    Attached Files Attached Files

  7. #27
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Well, yes, now you made it work like it did with H2 and it works again.

    Edit: Ignore, I didnt understand what you mean at first.

  8. #28
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Are you saying it now works?? If if so.................

    Hibernate 3 defaults to lazy initialization, this issue has been re-hashed lots of times on the web. I would google and see what you can find. The link I added discusses the changes from Hibernate 2 to 3. I wouldn't personally just change them to all be eager (non-lazy) and be happy with that. I'd have more of a think if it made sense to like that in the first place. If you aren't that bothered just change them and your system will function as before.

  9. #29
    Join Date
    Dec 2006
    Posts
    23

    Default

    You are telling me inserting null in a not nullable column does not throw anymore a HibernateException (that inherits from RuntimeException) and that is a normal behaviour?

    My test in S1.1.2 + H2 threw a HibernateException, so the session was rollbacked AND the connection was closed.

    now, there is no HibernateException (that could be a problem, I do not know yet) and the connection is closed.

  10. #30
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    You are not updating anything, that's the problem. The session is opened and closed in the first line, and the changes you do with setters are done only in memory.

    Anyway, what is the point of changing spring/hibernate version for you? Hibernate 3 changed a lot of things and not everything works as it used to. On the other hand you seem very inpatient at making it work again.

Posting Permissions

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