generated from pricelees/issue-pr-template
36 lines
883 B
Kotlin
36 lines
883 B
Kotlin
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?
|
|
|
|
}
|