[英]spring transactional annotated method without merge call on entities
We are using spring roo, and there are some methods in the codebase annotated with @Transactional. 我们正在使用spring roo,并且代码库中有一些用@Transactional注释的方法。
For example, 例如,
class XService {
@Transactional
public Response doSomething(String email) {
User u = User.findByEmail(email);
u.setLastModified(Calendar.getInstance());
return new Response("OK");
}
}
Notice that u.merge() is not called after setLastModified. 请注意,在setLastModified之后不会调用u.merge()。 What should be the value in lastModified column of user table after this method is complete.
此方法完成后,用户表的lastModified列中的值应该是什么。
Thanks! 谢谢!
Depending on: 取决于:
XService.doSomthing
is annotated with @Transactional
or not, and it ends with a RuntimeException
or not. XService.doSomthing
方法是否使用@Transactional
注释,并且是否以RuntimeException
结尾。 By default, if you call to XService.doSomthing
from a controller , the User instance should be updated as u
is an attached instance and method doesn't throw a runtime exception . 默认情况下,如果您从控制器调用
XService.doSomthing
,则应该更新User实例,因为u
是一个附加实例,并且方法不会引发运行时异常 。
Look at this post which I think can explain you interesting information about transaction behaviours on JPA. 看一下这篇文章 ,我认为它可以为您解释有关JPA上交易行为的有趣信息。
Good luck. 祝好运。
Where is " u.merge() " called? 在哪里调用“ u.merge() ”?
On the other side, Roo doesn't annotate each Service method with @Transactional , it annotates the entire Service at generated ITD. 另一方面,Roo不会使用@Transactional注释每个Service方法,而是使用生成的ITD注释整个Service。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.