Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Windows
- Git
- Java
- BPMN
- IntelliJ
- nginx
- JavaScript
- MySQL
- Spring
- LOG4J
- mybatis
- SAP
- database
- Linux
- gradle
- kubectl
- tibero
- log4j2
- maven
- JPA
- nodejs
- NCP
- useEffect
- gson
- Kubernetes
- springboot
- docker
- react
- dbeaver
- VSCode
Archives
- Today
- Total
두 손끝의 창조자
현재 스레드의 EntityManager 가져오기 본문
반응형
EntityManagerFactory는 DataSource와 연관되어 있다. 스프링 환경에서 사용하는 경우 EntityManagerFactory는 빈으로 등록해서 사용하는게 효율적이라 등록 후 사용중이라면 ApplicationContext에서 Factory를 가져올 수 있다.
@Transactional 로 트랜잭션 관리를 한다면
@PersistentContext 애노테이션으로 쉽게 현재 스레드의 EntityManager를 가져올 수 있다.
@PersistentContext
EntityMager em;
그러나 트랜젝션을 직접 관리한다면 아래 방법으로 가져올 수 있다.
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);반응형
Comments