generated from pricelees/issue-pr-template
feat: Auditing 및 Persist 설정이 담긴 BaseEntity 추가
This commit is contained in:
parent
d2e2c9c888
commit
769576a8d5
@ -3,7 +3,9 @@ package roomescape
|
||||
import org.springframework.boot.Banner
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing
|
||||
|
||||
@EnableJpaAuditing
|
||||
@SpringBootApplication
|
||||
class RoomescapeApplication
|
||||
|
||||
|
||||
35
src/main/kotlin/roomescape/common/entity/BaseEntity.kt
Normal file
35
src/main/kotlin/roomescape/common/entity/BaseEntity.kt
Normal file
@ -0,0 +1,35 @@
|
||||
package roomescape.common.entity
|
||||
|
||||
import jakarta.persistence.*
|
||||
import org.springframework.data.annotation.CreatedDate
|
||||
import org.springframework.data.annotation.LastModifiedDate
|
||||
import org.springframework.data.domain.Persistable
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener
|
||||
import java.time.LocalDateTime
|
||||
import kotlin.jvm.Transient
|
||||
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener::class)
|
||||
abstract class BaseEntity(
|
||||
@Column(updatable = false)
|
||||
@CreatedDate
|
||||
var createdAt: LocalDateTime? = null,
|
||||
|
||||
@LastModifiedDate
|
||||
var lastModifiedAt: LocalDateTime? = null,
|
||||
) : Persistable<Long> {
|
||||
|
||||
@Transient
|
||||
private var isNewEntity: Boolean = true
|
||||
|
||||
@PostLoad
|
||||
@PostPersist
|
||||
fun markNotNew() {
|
||||
isNewEntity = false
|
||||
}
|
||||
|
||||
override fun isNew(): Boolean = isNewEntity
|
||||
|
||||
abstract override fun getId(): Long?
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user