Skip to content

Instantly share code, notes, and snippets.

@lindabjalla
Created February 13, 2016 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindabjalla/88fd502bbd3792b69b0b to your computer and use it in GitHub Desktop.
Save lindabjalla/88fd502bbd3792b69b0b to your computer and use it in GitHub Desktop.
AbstractEntity
package se.grouprich.projectmanagement.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
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.jpa.domain.support.AuditingEntityListener;
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractEntity
{
@Id
@GeneratedValue
Long id;
@Column(nullable = false, unique = true)
Long controlNumber;
@Column(name = "createdBy")
@CreatedBy
private String createdBy;
@Column
@CreatedDate
private Date createdDate;
@Column
@LastModifiedBy
private String lastModifiedBy;
@Column
@LastModifiedDate
private Date lastModifiedDate;
protected AbstractEntity()
{
setControlNumber();
}
public Long getId()
{
return id;
}
public Long getControlNumber()
{
return controlNumber;
}
public void setControlNumber()
{
Date now = new Date();
Long time = now.getTime();
controlNumber = time;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment