Started transaction<READ COMMITTED> while nontransaction still active
时间: 2024-06-15 14:03:39 浏览: 19
当在非事务环境中执行了一个开始事务的操作时,会出现"Started transaction<READ COMMITTED> while nontransaction still active"的错误提示。这个错误通常发生在数据库操作中,表示在一个非事务的上下文中开始了一个事务。
在数据库中,事务是一组数据库操作的逻辑单元,要么全部执行成功,要么全部回滚。而非事务环境下的操作是即时执行的,没有事务的隔离和原子性。
当在非事务环境中执行了开始事务的操作时,数据库会发出警告或错误提示,因为这可能导致数据一致性问题。这是因为在非事务环境中的操作可能会与正在进行的事务产生冲突,破坏数据的一致性。
为了解决这个问题,你可以在开始事务之前先提交或回滚当前的非事务操作,或者将当前的非事务操作包装在一个事务中。这样可以确保在开始事务之前没有未完成的非事务操作。
相关问题
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <value>Teachinfo.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean>能在这里添加什么属性来防止只读吗
可以添加以下几个属性来防止只读:
1. `hibernate.connection.isolation`:设置数据库连接的隔离级别,可以将其设置为 `READ_COMMITTED` 或更高的级别,以确保只能进行读写操作而不是只读操作。
2. `hibernate.connection.autocommit`:将其设置为 `false`,以确保每个事务都需要手动提交或回滚,从而避免只读事务。
3. `hibernate.transaction.flush_before_completion`:将其设置为 `true`,以确保在事务提交之前,将所有挂起的更改立即刷新到数据库中,从而避免只读事务。
4. `hibernate.default_read_only`:将其设置为 `false`,以确保默认情况下可以进行写操作,从而避免只读事务。
5. `hibernate.connection.readOnly`:将其设置为 `false`,以确保连接不是只读连接,从而避免只读事务。
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager"/> </bean> <bean id="jbpmOAProcessServiceTransaction" parent="baseTransactionProxy" lazy-init="true"> <property name="target" ref="jbpmOAProcessService" /> <property name="transactionAttributes"> <props> <prop key="*"> PROPAGATION_REQUIRED,-BusinessServiceException </prop> </props> </property> </bean> 这个是部分xml配置
看起来你的配置是正确的。将目标对象jbpmOAProcessService设置为baseTransactionProxy的目标,并将事务属性设置为PROPAGATION_REQUIRED,表示如果当前没有事务,就创建一个新事务;如果已经有事务了,就加入到当前事务中。并且设置了回滚的异常类型BusinessServiceException。
但是,你提到JbpmTemplate的execute方法内部出现异常,事务没有回滚。这个问题可能是由于你的异常类型不是BusinessServiceException或其子类,或者异常被捕获并处理了,没有抛出RuntimeException或其子类。建议你在execute方法中添加日志或调试代码,确保异常被抛出并且类型正确。如果异常类型正确,可以尝试使用@Transactional注解替代TransactionProxyFactoryBean进行事务管理,看看是否可以解决问题。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)