gpt4 book ai didi

javax.persistence.TransactionRequiredException : no transaction is in progress in Spring 5

转载 作者:行者123 更新时间:2023-12-01 17:21:59 25 4
gpt4 key购买 nike

我正在 spring 3 和 hibernate 3 中进行产品构建,我已经更新了这个 hibernate 5 和 Spring 5。现在我可以部署应用程序,但是当我尝试连接数据库时得到这个“javax.persistence” .TransactionRequiredException:没有交易正在进行中”

<bean id="sessionFactoryBean"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceBean" />
<property name="annotatedClasses">
<!-- The model class is incorporated here -->
<list>
<value>com.test.ab.base.AaUser</value>
<value>com.test.ab.dealer.AaDealer</value>
<list>

<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryBean" />
</bean>

这是我的 Dao 层:

public class DatabaseConnection extends HibernateDaoSupport {

public DatabaseConnection (){

}

public static String QUERY_PREFIX_COUNT = "SELECT COUNT(*) ";

protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value)
throws HibernateException {

if (value instanceof Collection) {
queryObject.setParameterList(paramName, (Collection) value);
}
else if (value instanceof Object[]) {
queryObject.setParameterList(paramName, (Object[]) value);
}
else {
queryObject.setParameter(paramName, value);
}
}

protected String save(Object obj) throws HibernateException {
return getHibernateTemplate().save(obj).toString();
}

protected void update(Object obj) throws HibernateException {
getHibernateTemplate().update(obj);
}

//this is to be used to attached the detached object in session...
protected void merge(Object obj) throws HibernateException {
getHibernateTemplate().merge(obj);
}

protected void saveOrUpdObj(Object obj) throws HibernateException {
getHibernateTemplate().saveOrUpdate(obj);
}
}
javax.persistence.TransactionRequiredException: no transaction is in progress    at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:398)    at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3584)    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1462)    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1458)    at org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:148)    at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95)    at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:96)    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:919)    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:727)    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:631)    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385)    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)    at com.sun.proxy.$Proxy89.getAllAbModuleUserMapping(Unknown Source)    at com.actionbean.ab.base.WelcomeActionManager.fillModules(WelcomeActionManager.java:249)    at com.actionbean.ab.base.WelcomeActionManager.createUsrSessBean(WelcomeActionManager.java:211)    at com.actionbean.ab.base.WelcomeActionManager.retrieveSessionUserDataInternal(WelcomeActionManager.java:83)    at com.actionbean.ab.base.WelcomeActionManager.retrieveSessionUserData(WelcomeActionManager.java:61)    at com.actionbean.ab.base.WelcomeAction.performExecute(WelcomeAction.java:47)    at com.actionbean.ab.base.BaseAction.execute(BaseAction.java:153)    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at com.actionbean.ab.filter.AbFilter.doFilter(AbFilter.java:51)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:444)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)    at java.lang.Thread.run(Thread.java:748)javax.persistence.TransactionRequiredException: no transaction is in progress    at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:398)    at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3584)    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1462)    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1458)    at org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:148)    at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95)    at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:96)    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:919)    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:727)    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:631)    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385)    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)    at com.sun.proxy.$Proxy89.getAllAbModuleUserMapping(Unknown Source)    at com.actionbean.ab.base.WelcomeActionManager.fillModules(WelcomeActionManager.java:249)    at com.actionbean.ab.base.WelcomeActionManager.createUsrSessBean(WelcomeActionManager.java:211)    at com.actionbean.ab.base.WelcomeActionManager.retrieveSessionUserDataInternal(WelcomeActionManager.java:83)    at com.actionbean.ab.base.WelcomeActionManager.retrieveSessionUserData(WelcomeActionManager.java:61)    at com.actionbean.ab.base.WelcomeAction.performExecute(WelcomeAction.java:47)    at com.actionbean.ab.base.BaseAction.execute(BaseAction.java:153)    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at com.actionbean.ab.filter.AbFilter.doFilter(AbFilter.java:51)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:444)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)    at java.lang.Thread.run(Thread.java:748)

最佳答案

在 hibernate.cfg.xml 文件中使用以下属性

property -- >   hibernate.allow_update_outside_transaction = true

引用:https://developer.jboss.org/thread/278691

关于javax.persistence.TransactionRequiredException : no transaction is in progress in Spring 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61276947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com