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 537755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:57:37+00:00 2026-05-13T09:57:37+00:00

If you have a call in a Dao method like (pseudo code): return ..getHibernateTemplate(

  • 0

If you have a call in a Dao method like (pseudo code):

return ..getHibernateTemplate( get by id );

Now say that entity has a lazy-loaded collection. Once you return from your Dao using the hibernateTemplate helper method, how come the session stays in scope and allows you to lazy-load a collection?

Is the session initialized and committed at a global level on a per request basis?

Update

Please explain where exactly the call to ‘getcurrentsession’ is made, and when is it actually closed/committed?

From what I understand, the spring framework has to handle the session lifecycle, where does it do this? at what point the in the requests lifecycle?

It is handling the Unit of work also, where/how?

  • 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-13T09:57:37+00:00Added an answer on May 13, 2026 at 9:57 am

    Once you return from your Dao using the hibernateTemplate helper method, how come the session stays in scope and allows you to lazy-load a collection?

    Because the Session hasn’t been closed yet and your entity is thus still Persistent (as opposed to the Detached object state). As long as your entity has not been detached, you can lazy load collections and proxies. See chapter 10.1. Hibernate object states for more details on these states (it’s very important to understand them and the terminology used).

    Is the session initialized and committed at a global level on a per request basis?

    With web applications, it’s typically per request. As mentioned in the javadoc of HibernateTemplate:

    Lazy loading will also just work with an open Hibernate Session, either within a transaction or within OpenSessionInViewFilter/Interceptor.

    And if you look at the javadoc of OpenSessionInViewFilter or OpenSessionInViewInterceptor, you’ll read that they are slightly different but both binds a Hibernate Session to the thread for the entire processing of the request and provide an implementation of the “Open Session in View” pattern.

    Please explain where exactly the call to ‘getcurrentsession’ is made, and when is it actually closed/committed?

    You could look at the sources and use a debugger for this you know 🙂 Look at HibernateTemplate, more precisely the doExecute() method, this is where the session is obtained. For the close/commit, look at the previously mentioned OpenSessionInViewFilter/Interceptor, both have methods for this purpose.

    From what I understand, the spring framework has to handle the session lifecycle, where does it do this? at what point the in the requests lifecycle?

    I think I covered that part: the session is created at the start of a request and closed at the end.

    It is handling the Unit of work also, where/how?

    I’m not sure to get this one. To me, Hibernate’s Session is an implementation of the unit of work pattern. So this question is actually the same as the previous one.

    PS: I provided some links that show that everything is actually clearly documented. Spring and Hibernate have extremely nice documentation and javadoc. Take advantage of that, look at them by yourself, look at the code by yourself, use your debugger, you’ll learn a lot more.

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

Sidebar

Ask A Question

Stats

  • Questions 347k
  • Answers 347k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use Doctrine_Node_NestedSet::makeRoot() like so: $item->getNode()->makeRoot($maxRootValue + 1); You need to… May 14, 2026 at 6:21 am
  • Editorial Team
    Editorial Team added an answer I don't know if this will help you, but you… May 14, 2026 at 6:21 am
  • Editorial Team
    Editorial Team added an answer Check if the relevant page from CakePHP documentation can help… May 14, 2026 at 6:21 am

Related Questions

I am fairly new to StructureMap, but my understanding is that there are two
Let's say I have a set of Countries in my application. I expect this
I'm trying to brush up on my design pattern skills, and I'm curious what
We have a J2EE app built on Struts2+spring+iBatis; not all DAO's use iBatis...some code
Is using the 'synchronized' keyword on methods in a Java DAO going to cause

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.