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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:46:39+00:00 2026-05-17T15:46:39+00:00

I am using the Spring MVC framework with Hibernate. All of my controllers are

  • 0

I am using the Spring MVC framework with Hibernate. All of my controllers are using OpenSessionInViewInterceptor.

I am getting “could not initialize proxy – the owning Session was closed” errors in my controller’s onSubmit() method. I believe this is because Hibernate needs to go back to the database to fetch certain objects which were retrieved as proxies, and the OpenSessionInViewInterceptor has already closed the session.

I have been working around these problems by using HibernateTemplate().reattach() on the objects.

My questions are:

a) am I right in my diagnosis?
and b) is there a better way to re-open the Hibernate session? Is there a way to programmatically re-open a session in Hibernate without reattach()?

Edit: stack trace is below: when I iterate over the Set in my submit method I get the error

Data access failure: failed to lazily initialize a collection of role: com.companyname.apps.manager.domain.PriceChangeset.priceChanges, no session or session was closed

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.companyname.apps.manager.domain.PriceChangeset.priceChanges, no session or session was closed
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
    at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
    at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
    at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)
    **at com.companyname.apps.manager.service.impl.PriceChangesetServiceImpl.addChangesToSqlTransfer(PriceChangesetServiceImpl.java:263)
    at com.companyname.apps.manager.service.impl.PriceChangesetServiceImpl.approve(PriceChangesetServiceImpl.java:185)**
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:299)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy100.approve(Unknown Source)
    at com.companyname.apps.manager.webapp.controller.pricechanges.PriceChangeDetailsController.onSubmit(PriceChangeDetailsController.java:115)

Thanks!

  • 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-17T15:46:40+00:00Added an answer on May 17, 2026 at 3:46 pm

    OpenSessionInViewInterceptor is designed to hold the session open for the duration of a single request. It is not designed to keep sessions open across multiple requests. Indeed, doing such a thing is strongly discouraged. Sessions should be released once the request is complete.

    If you’re trying to re-attach a Hibernate object to a new session, as part of a new request, then you need to use something like reattach(), merge(), etc, on the Hibernate Session or EntitymManager. OpenSessionInViewInterceptor won’t help you out here.

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

Sidebar

Related Questions

i have been using the spring mvc frameworks lately for a university project. Could
While working on a Spring 3 MVC project using Hibernate, we encountered an annoying
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
I'm building a MVC web application (using the Spring MVC framework), and I'm a
I am writing Web app in java using Spring Web MVC framework. Somehow validation
Environment: The application is using Spring Framework 2.5.6.SEC01 and iBatis 2.3.4.726. It is MVC
I am doing a web site using spring mvc framework. I want to do
I'm thinking about the possibility of using Spring MVC with Vaadin Framework. Are there
I am using Spring framework mvc 3 + spring security 3. I would like
I'm using Spring MVC and jquery autocomplete, my spring controller looks like this @RequestMapping(value

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.