-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Feat/#450] v2 jpa 설정 추가 #461
base: dev
Are you sure you want to change the base?
Conversation
- EnableJpaRepositories - EntityTimeJsonFormat - JpaTransactional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseCase에 Tx 설정 수정해야해서 파일 체인지가 많은데
코멘트 위주로 확인해주시면 될 것 같습니다.
@Configuration | ||
@EnableJpaRepositories(basePackages = [ApiConfig.BASE_PACKAGE]) | ||
class ApiJpaConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
도메인 모듈을 추가하고 해당 모듈에서 JPA 설정을 해야한다면 위와 같이 설정하면 됩니다.
@Transactional | ||
@DataSourceTransactional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JPA가 추가되어 TX가 2개가 생겨 명확히 구분이 필요하여 수정하였습니다.
@MappedSuperclass | ||
@JsonIgnoreProperties(value = ["createdAt, modifiedAt"], allowGetters = true) | ||
@EntityListeners(AuditingEntityListener::class) | ||
abstract class BaseEntity { | ||
/** 생성일 */ | ||
@CreatedDate | ||
@Column(name = "created_at", columnDefinition = "datetime default CURRENT_TIMESTAMP") | ||
@EntityTimeJsonFormat | ||
var createdAt: LocalDateTime = LocalDateTime.now() | ||
|
||
/** 수정일 */ | ||
@LastModifiedDate | ||
@Column(name = "modified_at", columnDefinition = "datetime default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | ||
@EntityTimeJsonFormat | ||
var modifiedAt: LocalDateTime = LocalDateTime.now() | ||
|
||
/** 삭제 여부 */ | ||
@Column(name = "deleted", columnDefinition = "boolean default false") | ||
var deleted: Boolean = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseEntity 엔티티 입니다.
/** | ||
* org.springframework.data.jpa.repository.config.EnableJpaRepositories를 대체하는 애노테이션 | ||
* transactionManagerRef와 entityManagerFactoryRef는 JpaConfig에서 설정한 값을 기본으로 사용한다. | ||
* @see EnableJpaRepositories | ||
*/ | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@EnableJpaRepositories( | ||
transactionManagerRef = JpaConfig.JPA_TX, | ||
entityManagerFactoryRef = JpaConfig.JPA_EMF, | ||
) | ||
annotation class EnableJpaRepositories( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnableJpaRepositories를 대체하는 애노테이션 입니다.
/** | ||
* JPA 트랜잭션을 처리하는 어노테이션 | ||
* transactionManager는 JpaConfig에서 설정한 값을 기본으로 사용한다. | ||
*/ | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Transactional(transactionManager = JPA_TX) | ||
annotation class JpaTransactional( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JPA 트랜잭션을 처리하는 어노테이션
@Bean(name = [DATASOURCE_TX]) | ||
fun dataSourceTransactionManager(): PlatformTransactionManager = DataSourceTransactionManager(dataSource) | ||
|
||
override fun annotationDrivenTransactionManager(): TransactionManager = jpaTransactionManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TransactionManagementConfigurer
에서 annotationDrivenTransactionManager()를 오라이드 하면 기본 TX를 설정할 수 있다고 합니다.
저희는 V2에서 JPA를 사용할 예정이라 jpaTransactionManager()를 기본으로 설정하였습니다.
== @Transactional
을 transactionalManager 설정 없이 사용하여도 jpaTransactionManager로 설정된다는 의미
== JooQ 사용할 때 사용하는 dataSourceTransactionalManager는 @DataSourceTransactional
를 사용하면 됩니다.
🎫 연관 이슈
resolved: #450
💁♂️ PR 내용
🙏 작업
🙈 PR 참고 사항
📸 스크린샷
🚩 추가된 SQL 운영계 실행계획
🤖 테스트 체크리스트