Announcement Announcement Module
Collapse
No announcement yet.
hibernate4: No Session found for current thread Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hibernate4: No Session found for current thread

    Update:

    Now besides the "No Session found" exception I'm getting also:

    Code:
    NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session;
    See the whole stack in bellow post.


    I keep getting following exception:

    Code:
    org.hibernate.HibernateException: No Session found for current thread
    	org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
    	org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881)
    	com.project.server.dao.hibernate.UserDAOHibernateImpl.loadUserByUsername(UserDAOHibernateImpl.java:150)
    	com.project.server.dao.hibernate.UserDAOHibernateImpl.loadUserByUsername(UserDAOHibernateImpl.java:22)
    	org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices.processAutoLoginCookie(TokenBasedRememberMeServices.java:125)
    	org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.autoLogin(AbstractRememberMeServices.java:115)
    	org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:97)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
    	com.project.server.web.filters.CustomizedUsernamePasswordAuthenticationFilter.doFilter(CustomizedUsernamePasswordAuthenticationFilter.java:60)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
    	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    	org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
    	org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    	com.project.server.web.servlet.HttpsCookieFilter.doFilter(HttpsCookieFilter.java:35)
    	com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:65)
    Here is part of configuration from the applicaiton context:

    Code:
        
            <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            <property name="driverClass" value="${jdbc.driverClass}"/>
            <property name="jdbcUrl" value="${jdbc.url}"/>
            <!-- user/password overriden by env.properties -->
            <property name="user" value="${env.jdbc.user}"/>
            <property name="password" value="${env.jdbc.password}"/>
            <property name="testConnectionOnCheckout" value="true"/>
        </bean>
    
        <!-- Enable @Repository // from org.springframework.stereotype
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>  -->
        <bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>
    
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="packagesToScan" value="com.project.server.dao.hibernate"/>
            <property name="mappingResources">
                <list>
                    <value>com/project/server/domain/SomeObject.hbm.xml</value>
                     ...
                  
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
    
                    <prop key="hibernate.dialect">${db.dialect}</prop>
    
                    <prop key="hibernate.show_sql">false</prop>
                    <prop key="hibernate.format_sql">false</prop>
                    <prop key="hibernate.use_sql_comments">false</prop>
                    <prop key="hibernate.max_fetch_depth">1</prop>
    
                    <prop key="hibernate.cache.use_structured_entries">false</prop>
                    <prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
                    <prop key="hibernate.jdbc.batch_size">100</prop>
                    <prop key="hibernate.generate_statistics">false</prop>
    
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                    <prop key="hibernate.cache.use_second_level_cache">true</prop>
                    <prop key="hibernate.cache.use_minimal_puts">true</prop>
                    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                    <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
    
    
                    <!--hibernate search -->
                    <prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.impl.FSDirectoryProvider</prop>
                    <prop key="hibernate.search.default.indexBase">${server.compass.repo}</prop>
                    <prop key="hibernate.search.default.batch.merge_factor">3</prop>
                    <prop key="hibernate.search.id.new_generator_mappings">true</prop>
                    <prop key="hibernate.search.default.optimizer.operation_limit.max">1000</prop>
                    <prop key="hibernate.search.default.optimizer.transaction_limit.max">100</prop>
                    <prop key="hibernate.search.reader.strategy">not-shared</prop>
                    <prop key="hibernate.search.worker.execution">async</prop>
                    <prop key="hibernate.search.worker.thread_pool.size">20</prop>
                    <prop key="hibernate.search.worker.buffer_queue.max">100</prop>
    
                    <prop key="max_fetch_depth">1</prop>
    
    
                </props>
            </property>
        </bean>
    
        <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
    Please help me get rid of that error. Thanks!
    Last edited by momatej; Dec 10th, 2011, 10:11 AM.

  • #2
    I suggest a read of the transaction chapter... There is nothing that drives your transactions.. You have only a transaction manager no configuration on where/when to apply transactions.

    Also on another note your hibernate.connection and hibernate.c3p0 settings are useless so remove that clutter from your configuration. They are useless because you are injecting a datasource.

    Comment


    • #3
      Thank you for the suggestions!

      OK I have added to the application context:

      Code:
      <tx:annotation-driven/>
      Since all my service classes are marked as @Transactional

      And now I'm getting following exception:

      Code:
      java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session;
      	at org.springframework.orm.hibernate4.HibernateTransactionManager.doGetTransaction(HibernateTransactionManager.java:284)
      	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:335)
      	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
      	at com.iteezy.server.service.impl.UserServiceImpl$$EnhancerByCGLIB$$fe213902.getCurrentUser(<generated>)
      	at com.iteezy.server.web.servlet.ErrorServlet.doGet(ErrorServlet.java:40)
      	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 com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:59)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
      	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:473)
      	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
      	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
      	at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:455)
      	at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:399)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:191)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
      	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
      	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
      	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      	at java.lang.Thread.run(Unknown Source)
      Last edited by momatej; Dec 10th, 2011, 09:53 AM.

      Comment


      • #4
        Make sure you aren't mixing hibernate versions, that you use the latest snapshot version of spring 3.1 and that you use the latest hibernate 4 version.

        Comment


        • #5
          This has been resolved with SPR-8908: https://jira.springsource.org/browse/SPR-8908

          Comment


          • #6
            org.hibernate.HibernateException: No Session found for current thread

            I am also getting this exception. Please see the stack trace below. I am using spring 3.1 release version & hibernate 4.0 final

            org.hibernate.HibernateException: No Session found for current thread
            at org.springframework.orm.hibernate4.SpringSessionCo ntext.currentSession(SpringSessionContext.java:97)
            at org.hibernate.internal.SessionFactoryImpl.getCurre ntSession(SessionFactoryImpl.java:881)
            at com.creditjam.dao.hibernate.HibernateDao.findByNam edParam(HibernateDao.java:70)
            at com.creditjam.dao.hibernate.HibernateDao.executeQu ery(HibernateDao.java:249)
            at com.creditjam.dao.hibernate.HibernateAuthUserDao.c heckUserCredentials(HibernateAuthUserDao.java:18)
            at com.creditjam.service.impl.AuthenticationServiceIm pl.isValidUser(AuthenticationServiceImpl.java:27)
            at com.creditjam.manager.impl.AuthenticationManagerIm pl.verifyUser(AuthenticationManagerImpl.java:25)
            at com.creditjam.controller.AuthenticationController. verifyUser(AuthenticationController.java:40)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.springframework.web.method.support.InvocableHa ndlerMethod.invoke(InvocableHandlerMethod.java:212 )
            at org.springframework.web.method.support.InvocableHa ndlerMethod.invokeForRequest(InvocableHandlerMetho d.java:126)
            at org.springframework.web.servlet.mvc.method.annotat ion.ServletInvocableHandlerMethod.invokeAndHandle( ServletInvocableHandlerMethod.java:96)
            at org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerAdapter.invokeHandlerMeth od(RequestMappingHandlerAdapter.java:617)
            at org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerAdapter.handleInternal(Re questMappingHandlerAdapter.java:578)
            at org.springframework.web.servlet.mvc.method.Abstrac tHandlerMethodAdapter.handle(AbstractHandlerMethod Adapter.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.p rocessRequest(FrameworkServlet.java:882)
            at org.springframework.web.servlet.FrameworkServlet.d oGet(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.in ternalDoFilter(ApplicationFilterChain.java:304)
            at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
            at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:240)
            at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:164)
            at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:498)
            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(A ccessLogValve.java:562)
            at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
            at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:394)
            at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:243)
            at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:188)
            at org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:302)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
            at java.lang.Thread.run(Unknown Source)




            My configuration file is shown below.


            <contextroperty-placeholder location="classpath:config/db/database.properties" />

            <context:component-scan base-package="com.creditjam">
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Control ler" />
            <context:exclude-filter type="regex" expression="com\.creditjam\.entity\..*.class" />
            </context:component-scan>

            <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close"
            p:user="${DB.user}" password="${DB.password}" p:driverClass="${DB.driverClass}"
            p:jdbcUrl="${DB.jdbcUrl}" p:initialPoolSize="${DB.initialPoolSize}"
            p:maxPoolSize="${DB.maxPoolSize}" p:minPoolSize="${DB.minPoolSize}"
            p:acquireIncrement="${DB.acquireIncrement}" p:acquireRetryAttempts="${DB.acquireRetryAttempts} "
            p:acquireRetryDelay="${DB.acquireRetryDelay}"
            p:idleConnectionTestPeriod="${DB.idleConnectionTes tPeriod}"
            preferredTestQuery="${DB.preferredTestQuery}"
            p:numHelperThreads="${DB.numHelperThreads}"/>

            <bean id="sessionFactory"
            class="org.springframework.orm.hibernate4.LocalSes sionFactoryBean"
            p:dataSource-ref="dataSource" packagesToScan="com.creditjam.entity">
            <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <!-- <prop key="hibernate.current_session_context_class">org. springframework.orm.hibernate4.SpringSessionContex t</prop> -->
            </props>
            </property>
            </bean>

            <bean id="transactionManager" class="org.springframework.orm.hibernate4.Hibernat eTransactionManager"
            p:sessionFactory-ref="sessionFactory">
            <property name="hibernateManagedSession" value="true" />
            </bean>

            <tx:annotation-driven />

            <bean id="resource" class="org.springframework.core.io.ClassPathResour ce">
            <constructor-arg value="config/hibernate/query.properties"/>
            </bean>


            Please provide a solution

            Comment


            • #7
              First use [ code][/code ] tags when posting code that way it remains readable. Second use the search as this question has been answered numerous times before.

              Judging from your stack trace there is no proxy created which lets me believe you are scanning for services twice and thus have duplicate instances of your beans.

              Comment


              • #8
                Thanks Marten for the suggestions

                With some changes I run again. This time I get a little different stack trace but unable to identify what is the actual issue.

                Stack trace is showed below
                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.creditjam.dao.hibernate.HibernateDao.findByNamedParam(HibernateDao.java:71)
                	at com.creditjam.dao.hibernate.HibernateDao.executeQuery(HibernateDao.java:250)
                	at com.creditjam.dao.hibernate.HibernateAuthUserDao.checkUserCredentials(HibernateAuthUserDao.java:21)
                	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                	at java.lang.reflect.Method.invoke(Unknown Source)
                	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
                	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
                	at $Proxy24.checkUserCredentials(Unknown Source)
                	at com.creditjam.service.impl.AuthenticationServiceImpl.isValidUser(AuthenticationServiceImpl.java:27)
                	at com.creditjam.manager.impl.AuthenticationManagerImpl.verifyUser(AuthenticationManagerImpl.java:25)
                	at com.creditjam.controller.AuthenticationController.verifyUser(AuthenticationController.java:40)
                	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                	at java.lang.reflect.Method.invoke(Unknown Source)
                	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:498)
                	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:394)
                	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
                	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
                	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
                	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
                	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                	at java.lang.Thread.run(Unknown Source)
                I am giving my configuration files too
                web.xml

                Code:
                <context-param>
                		<param-name>log4jConfigLocation</param-name>
                		<param-value>/WEB-INF/log4j.xml</param-value>
                	</context-param>
                	<context-param>
                		<param-name>contextConfigLocation</param-name>
                		<param-value>WEB-INF/creditjam-persistence.xml</param-value>
                	</context-param>
                	<listener>
                		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                	</listener>
                	<listener>
                		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
                	</listener>
                	<servlet>
                		<servlet-name>creditjam</servlet-name>
                		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                		<init-param>
                		<param-name>contextConfigLocation</param-name>
                		<param-value>WEB-INF/creditjam-servlet.xml</param-value>
                		</init-param>
                		<load-on-startup>1</load-on-startup>
                	</servlet>
                	<servlet-mapping>
                		<servlet-name>creditjam</servlet-name>
                		<url-pattern>/</url-pattern>
                	</servlet-mapping>
                	<welcome-file-list>
                		<welcome-file>default.jsp</welcome-file>
                	</welcome-file-list>
                creditjam-servlet.xml
                Code:
                <context:component-scan base-package="com.creditjam" use-default-filters="false">
                		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
                	</context:component-scan>
                	
                	<mvc:annotation-driven />
                	
                	<mvc:view-controller path="login" view-name="login"/>
                	
                	<mvc:view-controller path="home" view-name="home"/>
                	
                	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                		p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1" />
                
                	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
                		p:basenames="config.i18n.*"/>
                	
                	<!-- Tile config start -->
                	<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"
                		p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView" p:order="0"/>
                		
                	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
                		p:definitions="/WEB-INF/tiles/tilesDefinition.xml"/>
                	<!-- Tile config end -->
                creditjam-persistence.xml
                Code:
                <context:property-placeholder location="classpath:config/db/database.properties" />
                	
                	<context:component-scan base-package="com.creditjam">
                		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
                		<context:exclude-filter type="regex" expression="com\.creditjam\.entity\..*.class" />
                	</context:component-scan>
                
                	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                		destroy-method="close"
                		p:user="${DB.user}" p:password="${DB.password}" p:driverClass="${DB.driverClass}"
                		p:jdbcUrl="${DB.jdbcUrl}" p:initialPoolSize="${DB.initialPoolSize}"
                		p:maxPoolSize="${DB.maxPoolSize}" p:minPoolSize="${DB.minPoolSize}"
                		p:acquireIncrement="${DB.acquireIncrement}" p:acquireRetryAttempts="${DB.acquireRetryAttempts}"
                		p:acquireRetryDelay="${DB.acquireRetryDelay}"
                		p:idleConnectionTestPeriod="${DB.idleConnectionTestPeriod}"
                		p:preferredTestQuery="${DB.preferredTestQuery}"
                		p:numHelperThreads="${DB.numHelperThreads}"/>
                	
                	<bean id="sessionFactory"
                		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
                		p:dataSource-ref="dataSource" p:packagesToScan="com.creditjam.entity">
                		<property name="hibernateProperties">
                            <props>
                                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                                <prop key="hibernate.hbm2ddl.auto">update</prop>
                                <prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
                                <prop key="hibernate.show_sql">false</prop>
                                <prop key="hibernate.format_sql">true</prop>
                                <prop key="hibernate.generate_statistics">true</prop>
                             </props>
                		</property>
                	</bean>
                	
                	<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
                		p:sessionFactory-ref="sessionFactory">
                		</bean>
                		
                	<tx:annotation-driven/>
                	
                	<bean id="resource" class="org.springframework.core.io.ClassPathResource">
                		<constructor-arg value="config/hibernate/query.properties"/>
                	</bean>

                Could u please provide a solution. If multiple scanning is happening what could b the problem?

                Comment


                • #9
                  Do you have a @Transactional on your classes? There is no transaction applied, judging from the stack trace. So you either have no @Transactional or have @Transactional on a class without interfaces and no cglib on your class path.

                  Comment


                  • #10
                    Yea its got resolved

                    Thanks a lot to Marten,

                    I had @Transactional at class but not in interface & no cglib.jar were there.

                    I added cglib.jar, ezmorph.jar & commons-lang.jar(Those were not in my classpath). And added @Transactional on interfaces too.

                    Actually I didn't have @Repository annotation on interfaces(Now I added). Was it a problem?


                    Thanks a lot

                    Cyril

                    Comment


                    • #11
                      Is this really fixed? I think I'm still getting this in my spring 3.1/hibernate 4.0 setup... Due to the nature of this problem I have posted my configs on StackOverflow to ensure that the problem doesn't lie with my setup.

                      http://stackoverflow.com/questions/8...nd-hibernate-4

                      The crux of it is I am still getting the following exception:
                      SEVERE: Servlet.service() for servlet [lystra] in context with path [/lystra] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread] with root cause org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionCo ntext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurre ntSession(SessionFactoryImpl.java:881)

                      Comment


                      • #12
                        I get the same exception using Spring 3.1.1.RELEASE with Hibernate 4.0.1.Final:
                        Code:
                        SEVERE: org.hibernate.HibernateException: No Session found for current thread
                        javax.faces.el.EvaluationException: org.hibernate.HibernateException: No Session found for current thread
                        	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                        	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                        	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
                        	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
                        	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
                        	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                        	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                        	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                        	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
                        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                        	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                        	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                        	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                        	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                        	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                        	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                        	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
                        	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                        	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                        	at java.lang.Thread.run(Thread.java:679)
                        Caused by: 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:883)
                        	at ro.kenjiru.yachin.persistence.HibernateListingDao.currentSession(HibernateListingDao.java:18)
                        	at ro.kenjiru.yachin.persistence.HibernateListingDao.addListing(HibernateListingDao.java:22)
                        	at ro.kenjiru.yachin.service.ListingServiceImpl.createListing(ListingServiceImpl.java:16)
                        	at ro.kenjiru.yachin.controller.ListingBean.addListing(ListingBean.java:35)
                        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                        	at java.lang.reflect.Method.invoke(Method.java:616)
                        	at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
                        	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                        	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:98)
                        	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                        	... 20 more
                        Mar 12, 2012 11:12:08 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
                        WARNING: #{listingBean.addListing}: org.hibernate.HibernateException: No Session found for current thread
                        javax.faces.FacesException: #{listingBean.addListing}: org.hibernate.HibernateException: No Session found for current thread
                        	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
                        	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
                        	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
                        	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
                        	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                        	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                        	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                        	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
                        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                        	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                        	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                        	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                        	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                        	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                        	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                        	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
                        	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                        	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                        	at java.lang.Thread.run(Thread.java:679)
                        Caused by: javax.faces.el.EvaluationException: org.hibernate.HibernateException: No Session found for current thread
                        	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                        	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                        	... 19 more
                        Caused by: 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:883)
                        	at ro.kenjiru.yachin.persistence.HibernateListingDao.currentSession(HibernateListingDao.java:18)
                        	at ro.kenjiru.yachin.persistence.HibernateListingDao.addListing(HibernateListingDao.java:22)
                        	at ro.kenjiru.yachin.service.ListingServiceImpl.createListing(ListingServiceImpl.java:16)
                        	at ro.kenjiru.yachin.controller.ListingBean.addListing(ListingBean.java:35)
                        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                        	at java.lang.reflect.Method.invoke(Method.java:616)
                        	at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
                        	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                        	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:98)
                        	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                        	... 20 more
                        I have a simple Dao:
                        Code:
                        @Repository
                        public class HibernateListingDao implements ListingDao {
                        	@Autowired(required=true)
                        	private SessionFactory sessionFactory;
                        
                        	public HibernateListingDao() { }
                        
                        	public Session currentSession() {
                        		return sessionFactory.getCurrentSession();
                        	}
                        
                        	public void addListing(Listing listing) {
                        		currentSession().save(listing);
                        	}
                        }
                        And a very simple service:
                        Code:
                        @Service
                        public class ListingServiceImpl implements ListingService {
                        	@Autowired
                        	private ListingDao listingDao;
                        	
                        	@Override
                        	public void createListing(Listing listing) {
                        		listingDao.addListing(listing);
                        	}
                        }
                        The bean looks like this:
                        Code:
                        @Component
                        @Scope("session")
                        public class HelloBean {
                        	private String name;
                        
                        	public String getName() {
                        		return name;
                        	}
                        
                        	public void setName(String name) {
                        		this.name = name;
                        	}
                        	
                        }
                        The application context file is:
                        Code:
                        <beans xmlns="http://www.springframework.org/schema/beans"
                        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                        	xmlns:context="http://www.springframework.org/schema/context"
                        	xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        		http://www.springframework.org/schema/context 
                        		http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                        
                        	<context:annotation-config />
                        	<context:component-scan base-package="ro.kenjiru.yachin" />
                        
                        	<bean id="dataSource"
                        		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                        
                        		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
                        		<property name="url" value="jdbc:hsqldb:mem://localhost/yachin" />
                        		<property name="username" value="sa" />
                        		<property name="password" value="" />
                        	</bean>
                        
                        	<bean id="sessionFactory"
                        		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
                        
                        		<property name="dataSource" ref="dataSource" />
                        		<property name="annotatedClasses">
                        			<list>
                        				<value>ro.kenjiru.yachin.domain.Listing</value>
                        			</list>
                        		</property>
                        		<property name="hibernateProperties">
                        			<props>
                        				<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                        				<prop key="hibernate.show_sql">true</prop>
                        				<prop key="hibernate.hbm2ddl.auto">create</prop>
                        			</props>
                        		</property>
                        	</bean>
                        	
                        	<bean id="listing" class="ro.kenjiru.yachin.domain.Listing" />
                        </beans>
                        Am I missing something obvious here?

                        Comment


                        • #13
                          You have nothing to drive your transactions, read the reference guide especially the transaction section and take a look at the reference/sample application(s).

                          Comment


                          • #14
                            I have a trouble, please help to resolve it!

                            Application context
                            Code:
                            <?xml version="1.0" encoding="UTF-8"?>
                            <beans xmlns="http://www.springframework.org/schema/beans"
                                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xmlns:tx="http://www.springframework.org/schema/tx"
                                   xsi:schemaLocation=
                                           "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
                            
                                <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                                    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
                                    <property name="url" value="jdbc:mysql://localhost:3306/security"/>
                                    <property name="username" value="root"/>
                                    <property name="password" value="root"/>
                                </bean>
                            
                                <bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
                                    <property name="dataSource" ref="dataSource"/>
                                    <property name="packagesToScan">
                                        <list>
                                            <value>name.shoo.springsecurity.entities</value>
                                        </list>
                                    </property>
                                    <property name="hibernateProperties">
                                        <props>
                                            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                                            <prop key="hibernate.hbm2ddl.auto">create</prop>
                                        </props>
                                    </property>
                                </bean>
                            
                                <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
                                    <property name="sessionFactory" ref="sessionFactory"/>
                                </bean>
                            
                                <tx:annotation-driven/>
                            
                            </beans>
                            DAO Implement
                            Code:
                            @Repository("usersDAO")
                            public class UsersDAOImpl implements UsersDAO{
                            
                                @Resource(name="sessionFactory")
                                SessionFactory sessionFactory;
                            
                                public String getSomething() {
                                    return (String)sessionFactory.getCurrentSession().toString();
                                }
                            }
                            Service
                            Code:
                            @Service("usersService")
                            public class UsersService {
                            
                                @Resource(name = "usersDAO")
                                UsersDAO usersDAO;
                            
                                @Transactional
                                public String doSomething() {
                                    return (String)usersDAO.getSomething().toString();
                                }
                            
                            }
                            Controller
                            Code:
                            @Controller
                            public class HomeController {
                            
                                @Resource(name="usersService")
                                UsersService usersService;
                            
                                @RequestMapping("/")
                                public String home() {
                            
                                    System.out.println(usersService.doSomething());
                            
                                    return "index";
                                }
                            And there is ERROR:
                            Code:
                            апр 18, 2012 4:50:45 PM org.apache.catalina.core.StandardWrapperValve invoke
                            SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread] with root cause
                            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:1039)
                            	at name.shoo.springsecurity.dao.UsersDAOImpl.getSomething(UsersDAOImpl.java:31)
                            	at name.shoo.springsecurity.services.UsersService.doSomething(UsersService.java:24)
                            	at name.shoo.springsecurity.controllers.HomeController.home(HomeController.java:28)
                            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                            	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                            	at java.lang.reflect.Method.invoke(Method.java:601)
                            	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
                            	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
                            	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
                            	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
                            	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
                            	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:224)
                            	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
                            	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
                            	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
                            	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
                            	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
                            	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
                            	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
                            	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
                            	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
                            	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
                            	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                            	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                            	at java.lang.Thread.run(Thread.java:722)

                            Comment


                            • #15
                              Please use the search as this question has been answered numerous times before...

                              Judging from your stacktrace and code you use component scanning and have duplicate components. How to overcome that is explained in the reference guide and answered many times on the forum before.

                              Comment

                              Working...
                              X