Programmer's path to quantitative transaction (17) -- Cointrader's Temporal entity (5); programmer's path to quantitative transaction
Reprint need to note: http://blog.csdn.net/minimicall,http://cloudtrader.top/
This section describes a time entity Temporal entity, and its code is very simple.
package org.cryptocoinpartners.schema;import java.util.Date;import javax.persistence.Basic;import javax.persistence.MappedSuperclass;import javax.persistence.Transient;import org.hibernate.annotations.Type;import org.joda.time.Instant;/** * @author Tim Olson */
// This annotation indicates that this class is also a base class and will not create a table in the Database @ MappedSuperclasspublic class Temporal extends EntityBase {public Temporal (Instant time) {super (); this. time = time; this. dateTime = time. toDate (); this. timestamp = time. getMillis ();}/** For Events, this is the time the Event itself occured, not the time we have Ed the Event. it shoshould be remote * server time if available, and local time if the object was created locally */
// @/Type annotation is used to describe the Type @ type (Type = "org. jadira. usertype. dateandtime. joda. persistentInstantAsMillisLong ") @ Basic (optional = false) public Instant getTime () {return time ;}// This annotation is used to indicate that the field is not stored in the database @ Transient public Date getDateTime () {return dateTime ;}@ Transient public long getTimestamp () {return timestamp;} // JPA protected Temporal () {} protected void setTime (Instant time) {this. time = time; this. dateTime = time. toDate (); this. timestamp = time. getMillis ();} protected Instant time; // time private long timestamp; // time cut private Date dateTime; // Date}
It must be noted that this class