I use Spring MVC. I have a problem with trigger my service --> dao method from jsp page. When I ask for jsp in a browser it shows me this:
I think the problem is with my xml application configuration. I read here that this type of problem occurs because Transactions not on properate place, not on Service layer, for me it seems like on proper just I use aop style to provide Transactions
My
is definitely where pointcut should execute, on each method of EducationWebServiceImpl class.
What is the problem???
I want to say, that this jsp page during rendering trigger dao methods to fetch some data from database for user to choose.
Servlet-context.xml
Code:
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)
Code:
<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 -->
Code:
<aop:pointcut id="eduWebPointcuts" expression="execution(*
edu.demidov.service.EducationWebServiceImpl.*(..))"/>
What is the problem???
I want to say, that this jsp page during rendering trigger dao methods to fetch some data from database for user to choose.
Servlet-context.xml
Code:
<!-- 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" />