Results 1 to 2 of 2

Thread: session.refresh() with Hibernate

  1. #1
    Join Date
    Apr 2006
    Posts
    10

    Default session.refresh() with Hibernate

    I am using Hibernate with Spring for my webapp with Declarative tx management. Everything works just fine except that I have run into a situation where I save an object into the database and then I need to get it back with session.refresh( object ) so that I can get all of it's relationships loaded into the session.

    I tried committing the Hibernate transaction right before I called the session.refresh(), but it did not work and got: "org.springframework.transaction.TransactionSystem Exception: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started".

    code looks like this:
    myDao.save( object );
    if( x==y )
    {
    //How do I commit transaction here, so that myDao.save() and myDao.refresh() both //work? or is there other way around?
    myDao.refresh( object );
    }

    Thanks.

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    If you are using declarative transactions then the tx will be committed after the method ends. Can you debug and add more logging and see why the transaction hasn't been started - the refresh is happening after the tx should already began?
    AFAIK, refresh should not influence the underlying transaction more then any other operations.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

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