Spring Framework
  1. Spring Framework
  2. SPR-8961

Regression: please expose Configuration object in Hibernate 4 LocalSessionFactoryBean

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 3.1 GA
    • Fix Version/s: 3.1.1
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Please expose Hibernate's org.hibernate.cfg.Configuration object in the newly added org.springframework.orm.hibernate4.LocalSessionFactoryBean class.

      Previous version org.springframework.orm.hibernate3.LocalSessionFactoryBean clearly does it through its #getConfiguration method. Today LocalSessionFactoryBuilder (i.e. Spring's extension of Hibernate's Configuration class) is only a local variable in the #afterPropertiesSet method.

      This is actually a very important piece of functionality for us.

      Thank you!

        Activity

        Hide
        Jonathan Lee added a comment -

        I am using the "simple" XML configuration to use hibernate4.LocalSessionFactoryBean as outlined in the documentaion for Spring 3.1.X.. however, I am not able to get the currentSession() from the session factory. I am unsure if I need to file a Jira, or if it is something that I am doing wrong.

        [code]org.hibernate.HibernateException: No Session found for current thread
        at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
        at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881)
        at com.matt2414.lystra.orm.UserDaoImpl.getAllUsers(UserDaoImpl.java:22)
        at com.matt2414.lystra.controllers.HomeController.home(HomeController.java:30)
        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:597)
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)[/code]

        Show
        Jonathan Lee added a comment - I am using the "simple" XML configuration to use hibernate4.LocalSessionFactoryBean as outlined in the documentaion for Spring 3.1.X.. however, I am not able to get the currentSession() from the session factory. I am unsure if I need to file a Jira, or if it is something that I am doing wrong. [code] org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881) at com.matt2414.lystra.orm.UserDaoImpl.getAllUsers(UserDaoImpl.java:22) at com.matt2414.lystra.controllers.HomeController.home(HomeController.java:30) 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:597) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) [/code]
        Hide
        Jonathan Lee added a comment -

        Could this issue be the root cause as to why I'm unable to get the currentSession like this?

        [code]Session session = sessionFactory.getCurrentSession();[/code]

        Show
        Jonathan Lee added a comment - Could this issue be the root cause as to why I'm unable to get the currentSession like this? [code] Session session = sessionFactory.getCurrentSession(); [/code]
        Hide
        Juergen Hoeller added a comment -

        Jonathan, your issue rather seems to relate to SPR-8998: At this point, the Hibernate 4 version of currentSession() only detects a Session within an actual transaction. See SPR-8998 for details.

        As for not exposing the Configuration object, this was intentional since earlier Hibernate 4 betas deprecated the Configuration approach in its entirety. However, as of Hibernate 4.0 GA, the Configuration still seems to be in place, with its deprecation deferred to Hibernate 5. So we'll see what we can do about exposing the Configuration object for Spring 3.1.1 now.

        Juergen

        Show
        Juergen Hoeller added a comment - Jonathan, your issue rather seems to relate to SPR-8998 : At this point, the Hibernate 4 version of currentSession() only detects a Session within an actual transaction. See SPR-8998 for details. As for not exposing the Configuration object, this was intentional since earlier Hibernate 4 betas deprecated the Configuration approach in its entirety. However, as of Hibernate 4.0 GA, the Configuration still seems to be in place, with its deprecation deferred to Hibernate 5. So we'll see what we can do about exposing the Configuration object for Spring 3.1.1 now. Juergen
        Hide
        Juergen Hoeller added a comment -

        As of Spring 3.1.1, LocalSessionFactoryBean has a public "getConfiguration()" accessor (as well as a protected "buildSessionFactory" template method that goes with it).

        Juergen

        Show
        Juergen Hoeller added a comment - As of Spring 3.1.1, LocalSessionFactoryBean has a public "getConfiguration()" accessor (as well as a protected "buildSessionFactory" template method that goes with it). Juergen

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Kyrill Alyoshin
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 13 weeks, 5 days ago