Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 未找到aop xml样式的当前线程休眠事务的会话_Hibernate_Spring Mvc_Transactions_Persistence_H2 - Fatal编程技术网

Hibernate 未找到aop xml样式的当前线程休眠事务的会话

Hibernate 未找到aop xml样式的当前线程休眠事务的会话,hibernate,spring-mvc,transactions,persistence,h2,Hibernate,Spring Mvc,Transactions,Persistence,H2,我使用SpringMVC。从jsp页面触发我的服务-->dao方法时出现问题。当我在浏览器中请求jsp时,它向我显示: 2013-07-19 07:55:32,385 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <DispatcherServlet with name 'appServlet' processing GET request for [/web/]> 2013-07-19 07:55:32,

我使用SpringMVC。从jsp页面触发我的服务-->dao方法时出现问题。当我在浏览器中请求jsp时,它向我显示:

  2013-07-19 07:55:32,385 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <DispatcherServlet with name 'appServlet' processing GET request for [/web/]>
2013-07-19 07:55:32,387 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - <Looking up handler method for path />
2013-07-19 07:55:32,388 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - <Did not find handler method for [/]>
2013-07-19 07:55:32,388 WARN [org.springframework.web.servlet.PageNotFound] - <No mapping found for HTTP request with URI [/web/] in DispatcherServlet with name 'appServlet'>
2013-07-19 07:55:32,388 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Successfully completed request>
2013-07-19 07:55:41,889 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <DispatcherServlet with name 'appServlet' processing GET request for [/web/input]>
2013-07-19 07:55:41,889 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - <Looking up handler method for path /input>
2013-07-19 07:55:41,891 DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - <Returning handler method [public java.lang.String edu.demidov.web.MainController.inputForm(edu.demidov.web.FormBackingObjectInput,org.springframework.ui.Model)]>
2013-07-19 07:55:41,891 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Returning cached instance of singleton bean 'mainController'>
2013-07-19 07:55:41,891 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Last-Modified value for [/web/input] is: -1>
2013-07-19 07:55:41,903 DEBUG [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver] - <Resolving exception from handler [public java.lang.String edu.demidov.web.MainController.inputForm(edu.demidov.web.FormBackingObjectInput,org.springframework.ui.Model)]: org.hibernate.HibernateException: No Session found for current thread>
2013-07-19 07:55:41,905 DEBUG [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver] - <Resolving exception from handler [public java.lang.String edu.demidov.web.MainController.inputForm(edu.demidov.web.FormBackingObjectInput,org.springframework.ui.Model)]: org.hibernate.HibernateException: No Session found for current thread>
2013-07-19 07:55:41,906 DEBUG [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] - <Resolving exception from handler [public java.lang.String edu.demidov.web.MainController.inputForm(edu.demidov.web.FormBackingObjectInput,org.springframework.ui.Model)]: org.hibernate.HibernateException: No Session found for current thread>
2013-07-19 07:55:41,907 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Could not complete request>
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:988)
    at edu.demidov.dao.EducationWebDaoImpl.fetchAllInstitutionNames(EducationWebDaoImpl.java:161)
    at edu.demidov.service.EducationWebServiceImpl.fetchAllInstitutionNamesService(EducationWebServiceImpl.java:82)
    at edu.demidov.web.MainController.prepareModelNames(MainController.java:39)
    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.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123)
    at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:722)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    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.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)
2013-07-19 07:55:32385调试[org.springframework.web.servlet.DispatcherServlet]-
2013-07-19 07:55:32387调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-
2013-07-19 07:55:32388调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-
2013-07-19 07:55:32388警告[org.springframework.web.servlet.PageNotFound]-
2013-07-19 07:55:32388调试[org.springframework.web.servlet.DispatcherServlet]-
2013-07-19 07:55:41889调试[org.springframework.web.servlet.DispatcherServlet]-
2013-07-19 07:55:41889调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-
2013-07-19 07:55:41891调试[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-
2013-07-19 07:55:41891调试[org.springframework.beans.factory.support.DefaultListableBeanFactory]-
2013-07-19 07:55:41891调试[org.springframework.web.servlet.DispatcherServlet]-
2013-07-19 07:55:41903调试[org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver]-
2013-07-19 07:55:41905调试[org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver]-
2013-07-19 07:55:41906调试[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]-
2013-07-19 07:55:41907调试[org.springframework.web.servlet.DispatcherServlet]-
org.hibernate.hibernateeexception:未找到当前线程的会话
位于org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
位于org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:988)
位于edu.demidov.dao.EducationWebDaoImpl.fetchAllInstitutionNames(EducationWebDaoImpl.java:161)
位于edu.demidov.service.EducationWebServiceImpl.fetchAllInstitutionNamesService(EducationWebServiceImpl.java:82)
位于edu.demidov.web.MainController.prepareModelNames(MainController.java:39)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:601)
位于org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
位于org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
位于org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123)
位于org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97)
位于org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:722)
位于org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
位于org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
位于org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
位于org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
位于org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
位于org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
位于javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
位于org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
位于javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
位于org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
位于org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
位于org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
位于org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
位于org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
位于org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
位于org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
位于org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
位于org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
位于org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
位于org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
位于org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
运行(Thread.java:722)
我认为问题在于我的xml应用程序配置。我在这里读到,发生这种类型的问题是因为事务不在适当的位置,不在服务层,对我来说,似乎是在适当的位置,只是我使用aop样式来提供事务

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- Using and configuring C3P0 proxy -->
        <property name="driverClass"><value>org.h2.Driver</value></property>
        <property name="jdbcUrl"><value>jdbc:h2:/home/vadim/workspace-sts/h2/EDUCATION</value></property>
        <property name="user"><value>sa</value></property>
        <property name="password"><value></value></property>
        <property name="initialPoolSize"><value>3</value></property> <!-- Number of Connections a pool will try to acquire upon startup -->
        <property name="minPoolSize"><value>1</value></property> <!-- Minimum connection pool size -->
        <property name="maxPoolSize"><value>20</value></property> <!-- Max connection pool size -->
        <property name="maxConnectionAge"><value>3600</value></property> <!-- Set max connection age to 1 hour, after it will release -->
        <property name="maxIdleTime"><value>600</value></property> <!-- 10 minutes connection can stay unused before be discarded -->
        <property name="checkoutTimeout"><value>240000</value></property> <!-- Each what time check for unused connections -->
        </bean>

    <!-- Declare Hibernate transaction manager. Realization of PlatformTransactionManager-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref ="sessionFactory"/>
    </bean>

    <tx:advice  id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="fetch*" propagation="REQUIRED" read-only="true" />
            <tx:method name="*"/>
        </tx:attributes>    
    </tx:advice>

    <aop:config>
        <aop:pointcut id="eduWebPointcuts" expression="execution(* edu.demidov.service.EducationWebServiceImpl.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="eduWebPointcuts"/> 
    </aop:config>

    <!-- Looks for specific annotation configuration in this packages -->
    <context:component-scan base-package="edu.demidov.dao, edu.demidov.service"/>

    <!-- Declare annotation configuration -->
    <context:annotation-config />

    <!-- Build sessionFactory annotation base configuration -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="dataSource" ref ="dataSource"/> <!-- Injecting datasource C3P0 to Hibernate sessionFactory datasource -->
        <property name="packagesToScan" value="edu.demidov.dto"/> <!-- Package will be scanned for entity classes -->

        <property name="hibernateProperties">   <!-- Configuring properties -->
            <props> 

                <prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop> <!-- Put dialect for particular database to use queries to this DB -->
                <prop key="show_sql">true</prop>


                <prop key="hibernate.c3p0.min_size">1</prop> <!-- Same to minPoolSize -->
                <prop key="hibernate.c3p0.max_size">20</prop> <!--Same to maxPoolSize -->
                <prop key="hibernate.c3p0.timeout">600</prop> <!-- Same to maxIdleTime -->
                <prop key="hibernate.c3p0.max_statements">5</prop> <!-- Set number of cached statements used often -->

                <prop key="hibernate.max_fetch_depth">3</prop>  <!-- Sets a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one) -->
                <prop key="hibernate.jdbc.fetch_size">30</prop> <!-- Declare how many records will get from database in one package -->
                <prop key="hibernate.jdbc.batch_size">15</prop> <!-- When it's a lot of queries in short time passed to database this put queries in one batch and send them to database -->
                <prop key="hibernate.show_sql">true</prop>

            </props>
       </property> <!-- End of configuration hibernateProperties -->

    </bean> <!-- End of configuring org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean -->

org.h2.Driver
jdbc:h2:/home/vadim/workspace sts/h2/EDUCATION
sa
3.
1.
20
3600
600
240000
 <aop:pointcut id="eduWebPointcuts" expression="execution(*
 edu.demidov.service.EducationWebServiceImpl.*(..))"/>
@SuppressWarnings("unchecked")
    @Override
    public List<String> fetchAllInstitutionNames() {        
        return sessionFactory.getCurrentSession().createQuery("select distinct institution.nameOfInstitution from InstitutionInForm institution").list();
    }


    @SuppressWarnings("unchecked")
    @Override
    public List<String> fetchAllInstitutionTypes() {        
        return sessionFactory.getCurrentSession().createQuery("select distinct institutionType.typeOfInstitution from InstitutionTypeInForm institutionType").list();
    }


    @SuppressWarnings("unchecked")
    @Override
    public List<Date> fetchAllDates() {
        return sessionFactory.getCurrentSession().createQuery("select distinct newDate.particularDate from FormDate newDate").list();
    }
<form:form modelAttribute="fboiAttributes" action="add" method="post">

<table align="center">

<tr><td> <form:label path="formDate.particularDate"/> <form:select path="formDate.particularDate"> <form:options items="${listOfDates}"/> </form:select> </td></tr>

<tr><td> <form:label path="institutions.nameOfInstitution"/> <form:select path="institutions.nameOfInstitution"> <form:options items="${listOfNames}"/> </form:select> </td></tr>

<tr><td> <form:label path="institutionType.typeOfInstitution"/> <form:select path="institutionType.typeOfInstitution"> <form:options items="${listOfTypes}"/> </form:select> </td></tr>

<tr><td> <form:label path="formDescription.daySchedule"/> <form:input path="formDescription.daySchedule"/> </td></tr>

<tr><td> <form:label path="formDescription.workScheduale"/> <form:input path="formDescription.workScheduale"/> </td></tr>

<tr><td> <form:label path="formDescription.rotation"/> <form:input path="formDescription.rotation"/> </td></tr>

<tr><td> <form:label path="formDescription.numberOfKids"/> <form:input path="formDescription.numberOfKids"/> </td></tr>

<tr><td> <form:label path="formDescription.kidsUnder3YearsOld"/> <form:input path="formDescription.kidsUnder3YearsOld"/> </td></tr>

<tr><td> <form:label path="formDescription.kidsUpper3YearsOld"/> <form:input path="formDescription.kidsUpper3YearsOld"/> </td></tr>

<tr><td> <form:label path="formDescription.kidsGoSchoolDate"/> <form:input path="formDescription.kidsGoSchoolDate"/> </td></tr>

<tr><td> <form:label path="formDescription.kidsGoSchoolNumber"/> <form:input path="formDescription.kidsGoSchoolNumber"/> </td></tr>

<tr><td> <input type="submit"/> </td></tr>

</table>

</form:form>
private static final Logger logger = LoggerFactory.getLogger(MainController.class);


    @Autowired
    private EducationWebServiceImpl educationWebServiceImpl;


    @ModelAttribute("listOfDates") 
    public List<Date> prepareModelDate() {      
        List<Date> listOfDates = educationWebServiceImpl.fetchAllDatesService();
        return listOfDates;     
    }

    @ModelAttribute("listOfNames")
    public List<String> prepareModelNames() {       
        List<String> listOfNames = educationWebServiceImpl.fetchAllInstitutionNamesService();
        return listOfNames;     
    }

    @ModelAttribute("listOfTypes")
    public List<String> prepareModelTypes() {       
        List<String> listOfTypes = educationWebServiceImpl.fetchAllInstitutionTypesService();
        return listOfTypes;     
    }


    @RequestMapping(value="/input", method=RequestMethod.GET)
    public String inputForm(FormBackingObjectInput fboi, Model model) {         
        model.addAttribute("fboiAttributes", fboi);         
        return "input";
    }
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/classes directory. Goes first -->
    <beans:bean id="xlsviewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <beans:property name="order" value="1" />
    <beans:property name="basename" value="views"/>
    </beans:bean>

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean id="jspviewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <beans:bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <beans:property name="basename" value="/resources/locale/messages"/>
    </beans:bean>

    <context:component-scan base-package="edu.demidov.web, edu.demidov.service, edu.demidov.dao" />