- 浏览: 23184 次
- 性别:
- 来自: 北京
最新评论
-
冲杯茶喝:
明显是自己没理解pipeline的机制,bootstrap.s ...
netty-3.2.4.Final IDLE时无法发送链路检测报文的BUG -
pudong:
如果hibernate.current_session_con ...
SSH下Hibernate事务问题createCriteria is not valid without active transaction -
gaolinwu:
该问题,正解。这个问题一直缠绕了我一天的时间,我换了好多的接口 ...
SSH下Hibernate事务问题createCriteria is not valid without active transaction -
banchun:
你说的这个版本的bug,我没用那个补丁包的情况下,心跳包为什么 ...
netty-3.2.4.Final IDLE时无法发送链路检测报文的BUG -
爱老虎哟:
你好,请问你这个问题解决了没?怎么解决的?
SSH下Hibernate事务问题createCriteria is not valid without active transaction
SSH下Hibernate事务问题createCriteria is not valid without active transaction
今天在ssh下又一次遇到事务问题,异常“ createCriteria is not valid without active transaction” 找来找去发现问题在于给hibernate配置中增加了如下属性导致:
去掉之后可以正常读写数据库了,目前还不知道是什么原因,哪位达人可以帮忙解释一下。
异常如下:
================================
web.xml
spring 配置文件:
<prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
去掉之后可以正常读写数据库了,目前还不知道是什么原因,哪位达人可以帮忙解释一下。
异常如下:
org.hibernate.HibernateException: createCriteria is not valid without active transaction at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:340) ~[hibernate-core-3.5.5-Final.jar:3.5.5-Final] at $Proxy56.createCriteria(Unknown Source) ~[na:na] at org.springside.modules.orm.hibernate.SimpleHibernateDao.createCriteria(SimpleHibernateDao.java:289) ~[springside3-core-3.3.4.jar:3.3.4] at org.springside.modules.orm.hibernate.SimpleHibernateDao.findUniqueBy(SimpleHibernateDao.java:173) ~[springside3-core-3.3.4.jar:3.3.4] at sms.web.service.AccountManager.findUserByLoginName(AccountManager.java:80) ~[AccountManager.class:na] at sms.web.service.AccountManager$$FastClassByCGLIB$$9f03f2c8.invoke(<generated>) ~[cglib-nodep-2.2.jar:na] at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) ~[cglib-nodep-2.2.jar:na] at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) ~[spring-tx-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE] at sms.web.service.AccountManager$$EnhancerByCGLIB$$f50196f0.findUserByLoginName(<generated>) ~[cglib-nodep-2.2.jar:na] at sms.web.actions.account.LoginAction$1.execute(LoginAction.java:59) ~[LoginAction$1.class:na] at base.action.WebSupport.actionExecute(WebSupport.java:228) ~[et-util-1.0-SNAPSHOT.jar:na] at sms.web.actions.account.LoginAction.execute(LoginAction.java:48) [LoginAction.class:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_23] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_23] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_23] at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_23] at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) [struts2-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) [struts2-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) [struts2-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) [struts2-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) [struts2-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) [struts2-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) [xwork-core-2.2.1.1.jar:2.2.1.1] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at sms.web.interceptor.CheckLoginFilter.intercept(CheckLoginFilter.java:79) [CheckLoginFilter.class:na] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at sms.web.interceptor.DebugInterceptor.intercept(DebugInterceptor.java:22) [DebugInterceptor.class:na] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) [struts2-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) [struts2-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) [struts2-core-2.2.1.1.jar:2.2.1.1] at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) [struts2-core-2.2.1.1.jar:2.2.1.1] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5] at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102) [struts2-core-2.2.1.1.jar:2.2.1.1] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5] at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) [catalina.jar:7.0.5] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [catalina.jar:7.0.5] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) [catalina.jar:7.0.5] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108) [catalina.jar:7.0.5] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558) [catalina.jar:7.0.5] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.5] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379) [catalina.jar:7.0.5] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243) [tomcat-coyote.jar:7.0.5] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259) [tomcat-coyote.jar:7.0.5] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237) [tomcat-coyote.jar:7.0.5] at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281) [tomcat-coyote.jar:7.0.5] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_23] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_23] at java.lang.Thread.run(Thread.java:662) [na:1.6.0_23]
================================
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>et platform</display-name> <!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔 此参数用于后面的Spring Context Loader --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:ctx-jms.xml classpath:ctx-platform.xml classpath:ctx-schedule.xml classpath:ctx-ws.xml </param-value> </context-param> <!-- CXF Servlet 配置 --> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/ws/*</url-pattern> </servlet-mapping> <!-- Filter 定义 --> <!-- Character Encoding filter --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <!-- Hibernate Open Session In View filter--> <filter> <filter-name>hibernateOpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <!-- SpringSecurity filter <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> --> <!-- Struts2 filter --> <filter> <filter-name>struts2CleanupFilter</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter> <filter-name>struts2Filter</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <!-- 下面的filter验证页面session是否已经成功登录--> <filter-mapping> <filter-name>hibernateOpenSessionInViewFilter</filter-name> <url-pattern>*.action</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> <filter-mapping> <filter-name>hibernateOpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>islogin</filter-name> <filter-class>sms.web.interceptor.CheckLoginFilter</filter-class> </filter> <filter-mapping> <filter-name>islogin</filter-name> <url-pattern>/pages/*</url-pattern> </filter-mapping> <!-- Filter 映射 --> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--<filter-mapping>--> <!--<filter-name>hibernateOpenSessionInViewFilter</filter-name>--> <!--<url-pattern>/j_spring_security_check</url-pattern>--> <!--</filter-mapping>--> <!--<filter-mapping>--> <!--<filter-name>springSecurityFilterChain</filter-name>--> <!--<url-pattern>*.action</url-pattern>--> <!--<dispatcher>REQUEST</dispatcher>--> <!--<dispatcher>FORWARD</dispatcher>--> <!--</filter-mapping>--> <!--<filter-mapping>--> <!--<filter-name>springSecurityFilterChain</filter-name>--> <!--<url-pattern>/j_spring_security_check</url-pattern>--> <!--<dispatcher>REQUEST</dispatcher>--> <!--<dispatcher>FORWARD</dispatcher>--> <!--</filter-mapping>--> <filter-mapping> <filter-name>struts2CleanupFilter</filter-name> <url-pattern>*.action</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> <filter-mapping> <filter-name>struts2Filter</filter-name> <url-pattern>*.action</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> <!--Spring的ApplicationContext 载入 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Spring 刷新Introspector防止内存泄露 --> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <!-- session超时定义,单位为分钟 --> <session-config> <session-timeout>20</session-timeout> </session-config> <!-- 出错页面定义 --> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/common_springside/500.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/common_springside/500.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/common_springside/404.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/common_springside/403.jsp</location> </error-page> </web-app>
spring 配置文件:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd" default-lazy-init="false"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <!-- 标准配置 --> <value>classpath*:/ctx-config/db.properties</value> <!-- 本地开发环境配置 --> <value>classpath*:/ctx.properties</value> <!-- 服务器生产环境配置 --> <value>file:/var/mini-service/application.server.properties</value> </list> </property> </bean> <bean id="springContextHolder" class="org.springside.modules.utils.spring.SpringContextHolder" lazy-init="false"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="initialPoolSize" value="${c3p0.initialPoolSize}"/> <property name="minPoolSize" value="${c3p0.minPoolSize}"/> <property name="maxPoolSize" value="${c3p0.maxPoolSize}"/> <property name="acquireIncrement" value="${c3p0.acquireIncrement}"/> <property name="maxIdleTime" value="${c3p0.maxIdleTime}"/> <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTextPeriod}"/> <property name="maxStatements" value="${c3p0.maxStatements}"/> <property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> [b] <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>[/b][color=red][/color] </props> </property> <property name="packagesToScan" value="sms.entities" /> </bean> <!-- 使Spring关注Annotation --> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --> <!-- 事务管理器配置,单数据源事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 使Spring关注Annotation --> <context:annotation-config /> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --> <context:component-scan base-package="sms" /> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="transactionManager"/> </bean> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager"/> <aop:config /> <aop:aspectj-autoproxy /> </beans>
评论
3 楼
pudong
2012-04-10
如果hibernate.current_session_context_class=thread去掉,则
Exception in thread "main" org.hibernate.HibernateException: No Session found for current thread
????
Exception in thread "main" org.hibernate.HibernateException: No Session found for current thread
????
2 楼
gaolinwu
2011-12-15
该问题,正解。
这个问题一直缠绕了我一天的时间,我换了好多的接口都不好使,就是因为我加了hibernate.current_session_context_class=thread导致,去掉这句话,问题“save is not valid without active transaction”一切正常。当然我想说的是这与配置有关,就看你怎么配置了,还有人碰到此问题话欢迎找我讨论linwu_gao@163.com,呵呵
这个问题一直缠绕了我一天的时间,我换了好多的接口都不好使,就是因为我加了hibernate.current_session_context_class=thread导致,去掉这句话,问题“save is not valid without active transaction”一切正常。当然我想说的是这与配置有关,就看你怎么配置了,还有人碰到此问题话欢迎找我讨论linwu_gao@163.com,呵呵
1 楼
爱老虎哟
2011-07-02
你好,请问你这个问题解决了没?怎么解决的?
相关推荐
本文将深入研究Hibernate中的`Session`和`Transaction`,这两个概念是理解Hibernate工作原理的关键。 首先,让我们了解`Session`。在Hibernate中,`Session`充当了应用程序与数据库之间的桥梁,它是持久化操作的...
SSH(Struts、Spring、Hibernate)是Java Web开发中常用的一种技术栈,其中Hibernate是一个强大的对象关系映射(ORM)框架。这篇文档将详细介绍Hibernate在应用开发中的基础使用,帮助初学者快速入门。 **SSH框架...
SSH框架,全称为Struts2、Spring和Hibernate的组合,是Java Web开发中常见的三大开源框架。这个压缩包文件提供了一个SSH框架模板以及使用Hibernate实现的分页功能的例子代码。 **Struts2** 是一个MVC(Model-View-...
5. **事务管理**:Hibernate 3.1提供了更强大的事务管理机制,支持JTA(Java Transaction API)和JPA的Transaction API,使得事务处理更加便捷。 6. **增强的性能**:包括对数据库连接池的改进,以及对查询执行效率...
//开始事务Transaction tx = session.beginTransaction(); //获取 UserTable 对象,假设已存在ID为1的用户UserTable userTable = (UserTable) session.get(UserTable.class, 1); //如果对象存在,执行删除操作if ...
Hibernate支持JTA(Java Transaction API)和JDBC事务管理。使用`Session`的`beginTransaction()`、`commit()`和`rollback()`方法可以处理事务。理解事务边界和回滚规则对于确保数据一致性至关重要。 9. 第一次运行...
在Java企业级开发中,Hibernate是一个非常重要的对象关系映射(ORM)框架,它极大地简化了数据库操作。本文将深入探讨在使用Hibernate进行MySQL查询时的一些关键知识点,以帮助开发者更好地理解和应用这些技术。 ...
- 编程式事务管理通过 `session.beginTransaction()`、`transaction.commit()` 和 `transaction.rollback()` 手动控制事务的开始、提交和回滚。 - 声明式事务管理通常通过 Spring 框架实现,利用 AOP(面向切面...
3. **Transaction**: 事务管理是Hibernate的重要部分,它提供了原子性、一致性、隔离性和持久性的保证。 4. **Query和Criteria API**: Hibernate提供了HQL(Hibernate Query Language)和Criteria API来执行查询...
`Session.beginTransaction()`开启事务,`Transaction.commit()`提交事务,`Transaction.rollback()`回滚事务。 在“hibernate003”这个案例中,作者很可能详细讲解了以上各个步骤,并给出了具体的代码示例,帮助...
本实例将深入探讨如何使用Hibernate实现用户注册和登录功能,这涉及到的主要知识点包括:Hibernate的基本配置、实体类定义、数据持久化、Session接口、Transaction管理以及SQL查询的映射。 首先,要使用Hibernate,...
- **Transaction**:处理事务,提供事务管理功能。 - **Criteria/Query**:提供了更高级别的查询API,可以动态构建查询条件。 ### 4. Hibernate的配置文件(`hibernate.cfg.xml`) 配置文件包含了数据库连接信息和...
4天的传智播客Hibernate框架课程将深入讲解这些知识点,并通过实际项目演示如何在开发中应用Hibernate,包括配置、实体映射、CRUD操作、事务管理、缓存优化等,帮助开发者快速掌握并熟练运用Hibernate框架。...
Hibernate是一个开源的对象关系映射(ORM)框架,它允许Java开发者在Java对象和数据库之间建立映射,从而简化数据操作。下面将详细讲解Hibernate的核心代码及其相关知识点。 1. **配置文件**: Hibernate的核心...
- **事务管理**:配置Hibernate如何处理事务,包括事务的隔离级别、回滚规则等。 #### 二、POJO(Plain Old Java Object) POJO,即“简单的老式Java对象”,是Hibernate中用来映射数据库表的一个核心概念。POJO...
SSH2 指的是 Struts2、Spring 和 Hibernate 三种技术的集成,这是一种常见的 Java Web 开发框架。本实例将介绍如何在 MyEclipse 6.0.1 开发环境中使用 SSH2 进行数据库操作,包括增、删、查、改的基本功能。 首先,...
4. **Transaction管理**:通过`Session.beginTransaction()`开始事务,`transaction.commit()`提交事务,`transaction.rollback()`回滚事务,确保数据操作的原子性。 5. **Criteria API的子查询**:可以创建子查询...
在实际项目中,为了防止并发问题,我们通常会使用事务管理。在上述操作前后,需要开启和提交事务。 ```java Transaction transaction = session.beginTransaction(); // ... 执行上述添加或查询操作 transaction....
6. Transaction:在Hibernate中,数据库操作通常在事务中进行,以确保数据的一致性。`Session`提供了开始、提交和回滚事务的方法。 7. HQL(Hibernate Query Language)或 Criteria API:这两者是Hibernate提供的...
Hibernate支持JTA(Java Transaction API)和JDBC事务管理。在应用程序中,可以通过编程式或声明式的方式来管理事务。 本教程的"基础Hibernate 教程.txt"文件,可能包含了关于这些知识点的详细讲解,包括代码示例和...