generated from pricelees/issue-pr-template
56 lines
1.4 KiB
Kotlin
56 lines
1.4 KiB
Kotlin
package roomescape.common.entity
|
|
|
|
import jakarta.persistence.Column
|
|
import jakarta.persistence.EntityListeners
|
|
import jakarta.persistence.Id
|
|
import jakarta.persistence.MappedSuperclass
|
|
import jakarta.persistence.PostLoad
|
|
import jakarta.persistence.PrePersist
|
|
import org.springframework.data.annotation.CreatedBy
|
|
import org.springframework.data.annotation.CreatedDate
|
|
import org.springframework.data.annotation.LastModifiedBy
|
|
import org.springframework.data.annotation.LastModifiedDate
|
|
import org.springframework.data.domain.Persistable
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener
|
|
import java.time.LocalDateTime
|
|
|
|
@MappedSuperclass
|
|
@EntityListeners(AuditingEntityListener::class)
|
|
abstract class AuditingBaseEntity(
|
|
@Id
|
|
@Column(name = "id")
|
|
private val _id: Long,
|
|
|
|
@Transient
|
|
private var isNewEntity: Boolean = true
|
|
) : Persistable<Long> {
|
|
@Column(updatable = false)
|
|
@CreatedDate
|
|
lateinit var createdAt: LocalDateTime
|
|
protected set
|
|
|
|
@Column(updatable = false)
|
|
@CreatedBy
|
|
var createdBy: Long = 0L
|
|
protected set
|
|
|
|
@Column
|
|
@LastModifiedDate
|
|
lateinit var updatedAt: LocalDateTime
|
|
protected set
|
|
|
|
@Column
|
|
@LastModifiedBy
|
|
var updatedBy: Long = 0L
|
|
protected set
|
|
|
|
@PostLoad
|
|
@PrePersist
|
|
fun markNotNew() {
|
|
isNewEntity = false
|
|
}
|
|
|
|
override fun getId(): Long = _id
|
|
override fun isNew(): Boolean = isNewEntity
|
|
}
|