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
.
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.
What I wanna know is :
- There is no transctional on service method. Why ? (If I change with MANDATORY propagation, it throws exception)
- my repository method which has
@Query
annotation works. I've thought that 'JPA requires transaction' but it wasn't. Why ?
I've searched this for a while, but couldn't understand. Can any one explain this or show me any article about ?
Thank you.