Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA의 영속성 컨텍스트를 비우는 로직을 AOP로 구현한다. #63

Open
sjhjack opened this issue Jan 24, 2025 · 0 comments
Open
Assignees

Comments

@sjhjack
Copy link
Contributor

sjhjack commented Jan 24, 2025

📑 개요

Member Domain의 Repository 테스트 코드를 작성하던 중 영속성 컨텍스트를 비우는 로직이 공통적으로 필요할 것이라는 생각이 들었습니다.

중복된 Member 저장 로직을 테스트하기 위해 Member 엔티티를 save 하고 같은 엔티티를 다시 save 한다면, 기존 Member는 이미 영속성 컨텍스트에 존재하므로 insert 쿼리가 아닌 update 쿼리가 발생하게 됩니다.
중복으로 인한 에러가 발생해야 하지만 성공적으로 쿼리가 수행되면서 테스트에 실패합니다.

현재는 new Member()를 통해 새로운 객체를 생성하는 방식으로 작성했지만, AOP를 활용하여 코드 재사용성을 향상시키는 것이 더 좋다고 생각합니다.

🚀 상세 작업 내용


  • EntityManager를 사용하여 영속성 컨텍스트를 비우는 로직을 AOP로 구현

⏰ 예상 소요 시간


3시간

📁 ETC


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant