diff --git a/data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java b/data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java new file mode 100644 index 00000000..d9539fd3 --- /dev/null +++ b/data/src/main/java/com/walking/data/entity/support/listener/TrafficEntitySoftDeleteListener.java @@ -0,0 +1,12 @@ +package com.walking.data.entity.support.listener; + +import com.walking.data.entity.traffic.TrafficEntity; +import javax.persistence.PreRemove; + +public class TrafficEntitySoftDeleteListener { + + @PreRemove + private void preRemove(TrafficEntity entity) { + entity.delete(); + } +} diff --git a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java index d2788657..e6eef41a 100644 --- a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java +++ b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java @@ -1,8 +1,10 @@ package com.walking.data.entity.traffic; +import com.walking.data.entity.support.listener.TrafficEntitySoftDeleteListener; import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -16,11 +18,13 @@ import org.locationtech.jts.geom.Point; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Entity +@EntityListeners({AuditingEntityListener.class, TrafficEntitySoftDeleteListener.class}) @Builder(toBuilder = true) @Table(name = "traffic") @SQLDelete(sql = "UPDATE traffic SET deleted=true where id=?")