[英]Spring @Transaction rolling back on completion of an action method
I have a method defined for an action button in JSF in the backing bean. 我在后备Bean中为JSF中的操作按钮定义了一个方法。 I am using Hibernate as the ORM.
我正在使用Hibernate作为ORM。 I am able to save the fresh data.
我能够保存新数据。 But when I try to update the same data, a transaction roll back exception is thrown
但是当我尝试更新相同的数据时,将引发事务回滚异常
javax.faces.FacesException: #{itemModificationBean.saveData('0','IM')}: org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
at
I have no interface implemented for the method and it is being called and defined in the backing bean itself. 我没有为该方法实现接口,并且它在后备bean本身中被调用和定义。
Is there any way to find out what is going wrong ?.... 有什么办法找出问题所在吗?
Any help would be appreciated 任何帮助,将不胜感激
Let me know if any more details are required to elaborate more on the issue 让我知道是否需要更多细节来详细说明这个问题
Backing Bean 菜豆
ItemBackingBean action method ItemBackingBean操作方法
@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
public String saveData(String action, String app) throws WFException {
setSaveOrSubmitStatus(action);
setCurrentApp(app);
//DB operations
.
.
.
.
.
return requestNo
}
The component 组件
<p:commandButton value="#{msg.save}" type="submit" id="modifySav"
process="@form @this"
action="#{itemModificationBean.saveData('0','IM')}"
rendered="#{itemAttributeBean.getRenderedValue('modifySav')}"
update="@([id$=form]) @([id$=collectionTab]) @([id$=itemRequestDetailsGrid]) @([id$=saveDialogItemMod])"
style="float:right;" />
From your stacktrace it is said that 从您的堆栈跟踪中得知
transaction has been marked as roll-back only
交易已被标记为仅回滚
I would suggest these steps: 我建议这些步骤:
transactionPropagation
strategies, you need to find out the first place where it is started. transactionPropagation
策略,因此您需要找出开始它的第一个位置。 From what I see from the qestion details it could be methods that are called from your backing bean saveData
method which are in the same transactional context. 根据我在问题详细信息中所看到的,它可能是在相同事务上下文中从后备bean
saveData
方法saveData
方法。 So update itself may work as it should be but previous method calls already marked current transaction as roll-back only. 因此,更新本身可能会正常工作,但以前的方法调用已将当前事务标记为仅回滚。 Check theirs transaction propagation strategies.
检查他们的交易传播策略。
I assume that some of the methods before database operation rolled back transaction by some exception or explicitly marked transaction as rolled-back only. 我假设数据库操作之前的某些方法由于某种异常而使事务回滚或将事务显式标记为仅回滚。 Those methods don't throw exception and that's why the program flow continue to database operation method call but it can't be done in the same transactional context.
这些方法不会引发异常,这就是程序流继续进行数据库操作方法调用的原因,但是不能在同一事务上下文中完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.