package com.lyubenblagoev.postfixrest.entity;

import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

@MappedSuperclass
public class BaseEntity {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	private boolean enabled;
	
	@CreatedDate
	private Date created;
	
	@LastModifiedDate
	private Date updated;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}

}

@@ -222,123 +222,152 @@
 ss;%0A
-%0A
 import 
-org.springframework.data.annotation.CreatedDate;%0Aimport org.springframework.data.annotation.LastModifiedDat
+javax.persistence.PrePersist;%0Aimport javax.persistence.PreUpdate;%0Aimport javax.persistence.Temporal;%0Aimport javax.persistence.TemporalTyp
 e;%0A%0A
@@ -522,86 +522,273 @@
 %09%0A%09@
-CreatedDate%0A%09private Date created;%0A%09%0A%09@LastModifiedDate%0A%09private Date updated;
+Temporal(TemporalType.TIMESTAMP)%0A%09private Date created;%0A%09%0A%09@Temporal(TemporalType.TIMESTAMP)%0A%09private Date updated;%0A%0A%09@PrePersist%0A%09public void onPrePersist() %7B%0A%09%09this.created = new Date();%0A%09%7D%0A%0A%09@PreUpdate%0A%09public void onPreUpdate() %7B%0A%09%09this.updated = new Date();%0A%09%7D
 %0A%0A%09p

Fix automatic update for the 'created' and 'updated' fields