[英]@Transactional not working from scheduled method
I have two classess as below.我有两个类如下。
@Component
@RequiredArgsConstructor
public class SomeScheduler {
private final SomeService someService;
@Scheduled( ... )
void doScheduledJob() {
someService.doJob();
}
}
@Service
@RequiredArgsConstructor
@Transactional
public class SomeService {
private final SomeRepository someRepository;
public void doJob() {
someRepository.findByCustomized();
...
}
}
The problem is that SomeService
is working without @Transactional
.问题是
SomeService
在没有@Transactional
的情况下工作。
With configuration in application.yml logging.level.org.springframework.transactional.interceptor: DEBUG
, I found that there are some logs like No need to create transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findByCustomized]: This method is not transactional.
通过 application.yml
logging.level.org.springframework.transactional.interceptor: DEBUG
中的配置,我发现有一些日志,例如No need to create transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findByCustomized]: This method is not transactional.
What I wanna know is:我想知道的是:
@Query
annotation works.@Query
注释的存储库方法有效。 I've thought that 'JPA requires transaction' but it wasn't. I've searched this for a while, but couldn't understand.我已经搜索了一段时间,但无法理解。 Can any one explain this or show me any article about?
任何人都可以解释这一点或向我展示任何有关的文章吗?
Thank you.谢谢你。
looks like "findByCustomized" is a non-modifiable query method (aka select), there is no need in transaction thus看起来“findByCustomized”是一种不可修改的查询方法(又名选择),因此在事务中不需要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.