- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 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
关于javax.persistence.TransactionRequiredException : no transaction is in progress in Spring 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61276947/
当我尝试使用 Hibernate 的多线程从数据库中删除数据时遇到问题。 repo : @Modifying @Query("DELETE FROM Customer cus WHERE cus.c
我在日志中收到异常: javax.persistence.TransactionRequiredException: Executing an update/delete query 这位于 upda
我正在运行 Karaf,我在 persistence.xml 中有一个数据源(指向 SQL Server DB),并且我正在尝试执行插入查询。 但是我遇到了这个异常: javax.persistenc
Spring MVC应用程序使用SpringDataJPA和休眠模式。生产模式利用了MySQL,但是对于单元测试,我已经设置了H2DB来运行,并且都使用单独的Java配置。该应用程序还利用了Sprin
这是我的存储库配置: @Configuration public class RepositoryConfing { @Bean public LocalContainerEntity
我有一个使用 Spring、Hibernate 和 JTA 的应用程序。 我们收到了一个数据大于预期的请求(10000 个元素),一般请求是 10-100 个元素。 在处理这个请求时,我们尝试在数据库
您好,我正在使用带有 spring 和 mongodb 的 hibernate JPA,并且我正在 Glassfish-4.0 上运行我的应用程序。 我的服务等级是: @Component publi
我正在尝试在 spring 中编写 2 个 native SQL 查询, 我在服务类中使用 SQL 的查询注释是: @Transactional @Scheduled(cron = "
我的 Controller 如下: @GetMapping("/groupByCourse") public Reply getStudentsCountByCourse(){
我正在开发一个简单的应用程序,其中数据库中的用户记录显示在 primefaces 数据表中,用户可以编辑或删除这些记录。这是 jsf 文件
我有异常(exception) javax.persistence.TransactionRequiredException: No transactional EntityManager ava
您好,我创建了一个简单的 JSF + JPA 应用程序。我的网络应用程序由一个 Entity、一个 ManagedBean 和一些 JSF 页面组成。它的目的是在 MySQL 数据库中创建和存储一个对
我想通过一个查询删除三个表中的相关数据。我收到错误消息:javax.persistence.TransactionRequiredException:执行更新/删除查询 我们使用 java 8、Hib
我有一个 Spring4 网络应用程序。最初我使用的是 Hibernate SessionFactory,并使用 Spring Hibernate API 进行开发。一切正常。也许愚蠢的是,我最近决定
TransactionRequiredException 的可能原因是什么? javax.ejb.EJBTransactionRolledbackException: JBAS011469: Tran
我有一个 CrudRepository 和一个删除数据的方法: public interface SampleRepository extends PagingAndSortingRepository
我有一个接受 POST 请求的 servlet,并且我正在尝试使用请求的参数来构建并保留实体类的实例。 这是我的 servlet: public class TheServlet extends Ht
我有以下类来使用实体管理器批量保存实体: @Repository @Transactional public class AbstractRepositoryAdapter { private
我有一个以 Hibernate 作为持久性提供者的 Spring/JPA 配置。但是我不明白为什么当我在没有打开事务的情况下对以下 DAO 代码调用 save() 时没有抛出 TransactionR
我有一个 Spring Boot 2 应用程序(仍处于开发阶段)与 JPA、hibernate 等一起运行良好。我现在进行的单一持久性测试通过正常。 但是,当我添加 @EnableBatchProce
我是一名优秀的程序员,十分优秀!