# @Scheduled 실행 시, Transaction처리

## 발생배경 <a href="#undefined" id="undefined"></a>

```
Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
```

* sheduler에서 트랜잭션을 관리하던 중 오류 발생.(JPA 사용)

## 원인

* 트랜잭션 매니저가 [@EnableTransactionManagement](https://github.com/EnableTransactionManagement)를 통해 DataSourceTransactionManager로 구성된 경우, 하이버네이트의 `begin()` 메소드가 AbstractTransactionImpl을 부르지 않는다고 한다.

## 해결

* @Schedule 클래스와 @Transacional이 있는 xxService를 분리.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mingeon-kim.gitbook.io/machine-geon-til/issue/jpa/scheduled-transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
