<aside> <img src="https://raw.githubusercontent.com/eirikmadland/notion-icons/master/v5/icon3/ul-github.svg" alt="https://raw.githubusercontent.com/eirikmadland/notion-icons/master/v5/icon3/ul-github.svg" width="40px" /> μ°Έμ‘° Github Code
</aside>
νΈλμμ
μ΄λ μ§μ(query)λ₯Ό νλμ λ¬Άμ μ²λ¦¬ν΄μ λ§μ½ μ€κ°μ μ€νμ΄ μ€λ¨λμ κ²½μ°, μ²μλΆν° λ€μ μ€ννλΒ Rollbackμ μννκ³ , μ€λ₯μμ΄ μ€νμ λ§μΉλ©΄Β commitμ νλ μ€ν λ¨μλ₯Ό μλ―Ένλ€. μ¦, ν λ² μ§μκ° μ€νλλ©΄ μ§μκ° λͺ¨λ μνλκ±°λ λͺ¨λ μνλμ§ μλΒ μμ
μνμ λ
Όλ¦¬μ λ¨μ
μ΄λ€.
μλ₯Ό λ€μ΄, μΉκ΅¬μκ² μΈν°λ· λ±
νΉμΌλ‘ 10,000μμ μ‘κΈνλ μν©μ μ€μ . Aκ° Bμκ² μ‘κΈμ νλ€λ©΄, Aμ κ³μ’μμ 10,000μμ μ°¨κ°νκ³ Bμ κ³μ’μ 10,000μμ μ¦κ°μμΌμΌ νλλ°, μ μ μλ μ€λ₯λ‘ μΈν΄ Aμ κ³μ’μμλ 10,000μμ΄ μ€μμ§λ§ μΉκ΅¬ κ³μ’μλ 10,000μμ΄ μ¦κ°λμ§ μλλ€λ©΄ λ°μνλ μΌμ? Aμ 10,000μμ κ·Έλ₯ 곡μ€μΌλ‘ μ¦λ°ν΄λ²λ¦¬λ λ¬Έμ κ° λ°μνλ€. μ΄λ¬ν κ²½μ°κ° μκΈ°μ§ μλλ‘ μ€κ°μ μ€λ₯κ° λ°μνλ©΄ λ€μ μ²μλΆν° μ‘κΈμ νλλ‘ νλ κ²μ΄ rollback
μ΄λ€. μ€λ₯ μμ΄ μ μμ μΌλ‘ μ‘κΈμ΄ λλ€λ©΄ μ μμ μΌλ‘ μ€νμ΄ λλ¬μΌλ―λ‘ commit
μ²λ¦¬ μ¦, μ‘κΈ κ³Όμ μ νλμ νΈλμμ
μ΄λΌ λ³Ό μ μλ€.
νΈλμμ μλ μλμ κ°μ΄ 4κ°μ§μ νΉμ±μ΄ μλ€. 4κ°μ§ νΉμ±μ μ κΈμλ§ λ°μΒ ACID νΉμ±μ΄λΌκ³ νλ€.
private final EntityManager em;
// νΈλμμ¨ μ¬μ© μ
EntityTransaction transaction = em.getTransaction();
try {
transaction.begin();
Developer developer = Developer.builder()
.developerLevel(DeveloperLevel.JUNGNIOR)
.developerSkillType(DeveloperSkillType.FRONT_END)
.experienceYear(2)
.name("Olaf")
.age(5)
.build();
developerRepository.save(developer);
transaction.commit();
} catch (Exception em) {
log.error("error : " + em.toString());
transaction.rollback();
throw new RuntimeException();
}
@Transactional