简体   繁体   English

在实体上没有合并调用的Spring事务注释方法

[英]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: 取决于:

  1. Method which calls XService.doSomthing is annotated with @Transactional or not, and it ends with a RuntimeException or not. 调用XService.doSomthing方法是否使用@Transactional注释,并且是否以RuntimeException结尾。
  2. Default Transactional propagation behaviour configuration. 默认事务传播行为配置。

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.

相关问题 从另一个@Transactional注释方法调用@Transactional注释方法 - Call @Transactional annotated method from another @Transactional annotated method Spring AOP:具有@Transactional注释方法的方法的注释切入点? - Spring AOP : Annotated pointcuts for a method with @Transactional annotated method? 回滚 @Transactional 注释的方法 - Rollback a @Transactional annotated method 从Spring Boot测试调用的@Caching方法[注有@Transactional]无法正常工作 - @Caching method called from spring boot test [annotated with @Transactional] not working 如果在内部@Spring注释了方法,则Spring @Transactional注释方法是否会覆盖@Transactional(readOnly = true)方法? - Does a Spring @Transactional annotated method overwrite an @Transactional(readOnly=true) method if called within it? Spring 没有为 @service 注释的 class 创建 bean,当它的方法之一用 @transactional 注释时 - Spring is not creating the bean for @service annotated class when one of its method is annotated with @transactional Spring:调用事务性方法的方法必须是事务性的? - Spring: A method who call a transactional method has to be transactional? Spring Boot 使用@Transactional 注解方法,调用其他事务性方法并抛出异常 - Spring Boot With @Transactional annotated method, calls other transactional methods and throws an Exception 与方法注解者@Transactional的通信 - Communication to caller of method annotated @Transactional Spring数据如何在事务方法中清理持久化实体? - How spring data clean persited entities in transactional method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM