Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5961587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:59:08+00:00 2026-05-22T18:59:08+00:00

org.hibernate.LazyInitializationException: could not initialize proxy – no Session was giving me a lot of

  • 0

“org.hibernate.LazyInitializationException: could not initialize proxy – no Session“ was giving me a lot of pain. Some of the old thread of stackoverflow has discussions about this particular problem. I followed those and solved the problem.

In my hibernate mapping xml I have added lazy="false" to classes tags and to the tags collections like set and list.

<class name="User" table="users" lazy="false">
    <id name="id" column="id">
        <generator class="native"/>
    </id>        
    <property name="type" column="type"/>         
    <many-to-one name="parent" column="parent"/>
    <property name="loginName" column="login_name" unique="true" not-null="true" index="idx_users_login_name" length="50"/>
    <property name="name" column="name" length="50"/>
    <property name="password" column="password"/>
    <property name="email" column="email" length="50"/>
    <property name="locale" column="locale" length="20"/>
    <property name="locked" column="locked"/>
    <many-to-one name="metadata" column="metadata_id"/>
    <set name="userSpaceRoles" cascade="all" inverse="true" lazy="false">
        <key column="user_id"/>
        <one-to-many class="UserSpaceRole"/>
    </set>      
</class>

<class name="UserSpaceRole" table="user_space_roles" lazy="false">
    <id name="id" column="id">
        <generator class="native"/>
    </id>
    <many-to-one name="user" column="user_id"/>
    <many-to-one name="space" column="space_id"/>
    <property name="roleKey" column="role_key" not-null="true"/>
</class>   

Thus the problem was solved.

  • Is lazy="flase" the only solution?
  • What happened if I set lazy="false"?
  • Should I specify lazy="false" in the class tag?

For more information I am using JBoss 4.2.0.GA and I was facing this problem whenever I restart the server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:59:09+00:00Added an answer on May 22, 2026 at 6:59 pm

    Instead of using lazy="false" on the class element, you are better off using it on the collections. That is, for example, whenever you fetch a User object, since the collection to UserSpaceRole is marked as not-lazy, the collection will be fetched as well.

    Using lazy="false" at the class element has some undesired consequences. Normally, when the collection is not lazy as I said above, the entire collection is fetched using either join, select or subselect, depending on your fetching strategy. For example, with select strategy, when you fetch a User from the db, hibernate issues two select statements: one for the user itself, and one for the collection. However, hibernate may choose to proxy the individual elements inside the collection.
    With lazy="false", hibernate can’t proxy those objects, and typically resorts to using a single query with a join between the two tables. That may not always be desired.

    However, the correct approach is look at your architecture and understand why the exception occurred in the first place. You have tried to access a property or a collection from a detached object (see here) after you already closed the session. I’d look at the service layer and see how can I fetch all the data needed before closing the session and passing the objects to the caller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: org.hibernate.LazyInitializationException: could not initialize proxy - no Session This is my service:
Error: org.hibernate.LazyInitializationException SEVERE: could not initialize proxy - the owning Session was closed Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: pojo.Person.address, no session or session
I'm getting this Hibernate error: org.hibernate.MappingException: Could not determine type for: a.b.c.Results$BusinessDate, for columns:
exception javax.servlet.ServletException: org.hibernate.exception.GenericJDBCException: could not execute query org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause
I'm a beginner in hibernate.I saw some samples in the internet, org.hibernate.Session session; //assuming
Despite using configuration below I got lazy initialize error: org.hibernate.LazyInitializationException: failed to lazily initialize
Where are the most common places where you've gotten an org.hibernate.LazyInitializationException in Grails, what
I am using Hibernate and getting Exception in thread main org.hibernate.ObjectNotFoundException: No row with
I get a Caused by: org.hibernate.SessionException: Session is closed! error when I click on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.