Results 1 to 2 of 2

Thread: Could not initialize proxy - no Session

Hybrid View

  1. #1

    Default Could not initialize proxy - no Session

    I have been struggling with this for a whlle. I have the following HQL:

    Code:
    SELECT prosocUser FROM ProsocUser AS prosocUser LEFT JOIN FETCH prosocUser.prosocPermissions WHERE prosocUser.userId = :userId
    and it seems to work OK (I think). When I try and access the prosocPermissions objects using:

    Code:
    prosocUser.getProsocPermissions();
    I get the error:

    Code:
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    I know this is being thrown because the hibernate session has been closed but I can't figure out the solution to it. I am using:

    Code:
    sessionFactory.getCurrentSession()
    and I think that means that the session is closed before processing gets to the view stage which is where I am trying to access the hibernate proxy object. I have however tried to use:

    Code:
    org.hibernate.Hibernate.initialize(prosocUser.getProsocPermissions());
    but to no effect.

    Can anyone help me out?
    Last edited by klogger; Apr 18th, 2009 at 04:59 PM.

  2. #2

    Default

    I got it working as soon as I woke up this morning. I had been getting confused with hibernate in general and had simplified my query in order to understand things better. Once I got the query correct I hadn't un-simplified it. It needed an additional JOIN to make it work.

Posting Permissions

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