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 | 29 | 30 | 31 |
Tags
- NCP
- mybatis
- SAP
- gson
- MySQL
- docker
- maven
- Linux
- springboot
- database
- IntelliJ
- LOG4J
- log4j2
- Windows
- Spring
- Git
- BPMN
- JavaScript
- tibero
- dbeaver
- Java
- Kubernetes
- useEffect
- JPA
- nginx
- react
- nodejs
- gradle
- sapfiorielements
- VSCode
Archives
- Today
- Total
두 손끝의 창조자
현재 스레드의 EntityManager 가져오기 본문
EntityManagerFactory는 DataSource와 연관되어 있다. 스프링 환경에서 사용하는 경우 EntityManagerFactory는 빈으로 등록해서 사용하는게 효율적이라 등록 후 사용중이라면 ApplicationContext에서 Factory를 가져올 수 있다.
@Transactional 로 트랜잭션 관리를 한다면
@PersistentContext 애노테이션으로 쉽게 현재 스레드의 EntityManager를 가져올 수 있다.
@PersistentContext
EntityMager em;
그러나 트랜젝션을 직접 관리한다면 아래 방법으로 가져올 수 있다.
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
반응형
Comments