The most important restriction when working in a transaction is to ALWAYS use the provided instance of entity manager - transactionalEntityManager in this example. DO NOT USE GLOBAL ENTITY MANAGER. All operations MUST be executed using the provided transactional entity manager.
await myDataSource.manager.transaction(async (transactionalEntityManager) => {
await transactionalEntityManager.save(users)
await transactionalEntityManager.save(photos)
// ...
})
오, 멘토님에게 피드백 받은 isolation levels가 공식문서에 있었네.
첫 번째 파라미터도 isolation levels를 넘긴다.
await myDataSource.manager.transaction(
"SERIALIZABLE",
(transactionalEntityManager) => {},
)
(MySQL, Postgres, SQL Server)
Oracle only supports the READ COMMITTED and SERIALIZABLE isolation levels.