I am using JPA for my database work and I need to create a database entity superclass which all of my table entities will extend.
Every database entity will have a primary key named id
(which in some cases is an int
and in some a String
) and also a lastUpdate
field which stores the time at which the database row was last updated (set from within the code).
DatabaseEntity
superclass:
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
public class DatabaseEntity <T> {
@Id
@Basic(optional = false)
@Column(name = "id")
private T _id;
@Basic(optional = false)
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_update")
private Date _lastUpdate;
public T getId() {
return _id;
}
public void setId(T id) {
_id = id;
}
public Date getLastUpdate() {
return _lastUpdate;
}
public void setLastUpdate() {
_lastUpdate = new Date();
}
}
Anything that I am doing wrong or that I should add in the superclass?