Java tutorial
/* * Copyright 2005-2013 shopxx.net. All rights reserved. * Support: http://www.shopxx.net * License: http://www.shopxx.net/license */ package net.groupbuy.entity; import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.EntityListeners; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.validation.groups.Default; import net.groupbuy.listener.EntityListener; import org.hibernate.search.annotations.DateBridge; import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Index; import org.hibernate.search.annotations.Resolution; import org.hibernate.search.annotations.Store; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonProperty; /** * Entity - * * @author SHOP++ Team * @version 3.0 */ @JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, creatorVisibility = Visibility.NONE) @EntityListeners(EntityListener.class) @MappedSuperclass public abstract class BaseEntity implements Serializable { private static final long serialVersionUID = -67188388306700736L; /** "ID"?? */ public static final String ID_PROPERTY_NAME = "id"; /** ""?? */ public static final String CREATE_DATE_PROPERTY_NAME = "createDate"; /** ""?? */ public static final String MODIFY_DATE_PROPERTY_NAME = "modifyDate"; /** * ?? */ public interface Save extends Default { } /** * ? */ public interface Update extends Default { } /** ID */ private Long id; /** */ private Date createDate; /** */ private Date modifyDate; /** * ?ID * * @return ID */ @JsonProperty @DocumentId @Id // MySQL/SQLServer: @GeneratedValue(strategy = GenerationType.AUTO) // Oracle: @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequenceGenerator") @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequenceGenerator") public Long getId() { return id; } /** * ID * * @param id * ID */ public void setId(Long id) { this.id = id; } /** * ? * * @return */ @JsonProperty @Field(store = Store.YES, index = Index.UN_TOKENIZED) @DateBridge(resolution = Resolution.SECOND) @Column(nullable = false, updatable = false) public Date getCreateDate() { return createDate; } /** * * * @param createDate * */ public void setCreateDate(Date createDate) { this.createDate = createDate; } /** * ? * * @return */ @JsonProperty @Field(store = Store.YES, index = Index.UN_TOKENIZED) @DateBridge(resolution = Resolution.SECOND) @Column(nullable = false) public Date getModifyDate() { return modifyDate; } /** * * * @param modifyDate * */ public void setModifyDate(Date modifyDate) { this.modifyDate = modifyDate; } /** * ?equals * * @param obj * * @return ? */ @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (this == obj) { return true; } if (!BaseEntity.class.isAssignableFrom(obj.getClass())) { return false; } BaseEntity other = (BaseEntity) obj; return getId() != null ? getId().equals(other.getId()) : false; } /** * ?hashCode * * @return hashCode */ @Override public int hashCode() { int hashCode = 17; hashCode += null == getId() ? 0 : getId().hashCode() * 31; return hashCode; } }