[英]@Transactional is giving error on Grails method
I am using Grails 2.1.1. 我正在使用Grails 2.1.1。 In a controller I have a method on top I have used
org.springframework.transaction.annotation.Transactional
as follows: 在控制器中,我上面有一个方法,我使用了
org.springframework.transaction.annotation.Transactional
,如下所示:
@Transactional
def saveItem() {
...
}
Then it is giving this error in the console: java.lang.reflect.InvocationTargetException
and showing only some code in the browser instead of form element. 然后,它在控制台中给出此错误:
java.lang.reflect.InvocationTargetException
并在浏览器中仅显示一些代码,而不是表单元素。 But if I remove @Transactional
from on top of the method the view is rendering fine. 但是,如果我从方法的顶部删除
@Transactional
,则视图呈现良好。
What am I missing here? 我在这里想念什么?
The support for @Transactional
annotation was introduced in Grails 2.3.x so it's not working in your case and your Grails version is older. 对
@Transactional
批注的支持是在Grails 2.3.x中引入的,因此在您的情况下不起作用,并且您的Grails版本较旧。
As a workaround, either you can move all your controller business logic code to a Grails service (which are transactional by default) or wrap your controller code inside withTransaction
method. 解决方法是,您可以将所有控制器业务逻辑代码移至Grails服务(默认情况下为事务性),或将控制器代码包装在
withTransaction
方法中。
@Transactional
def saveItem() {
AnyDomain.withTransaction {
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.