JPA中关于MS SQL Server数据库的TimeStamp数据类型如何映射

废话不说,多上代码,主要是看lastEditDate字段的定义:

 

package pojo;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 * @author chaijunkun
 * 文章表
 */
@Entity
public class Articles implements Serializable {
	/**
	 * 序列化版本唯一识别码
	 */
	private static final long serialVersionUID = 2522922473212237043L;

	/**
	 * 文章索引ID
	 */
	@Id
	@GeneratedValue
	private Long articleId;
	
	/**
	 * 文章标题
	 */
	private String articleName;
	
	/**
	 * 文章内容
	 */
	private String articleContent;
	
	/**
	 * 最后编辑时间
	 */
	@Column(columnDefinition="TIMESTAMP", insertable = false, updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastEditDate;

	public Long getArticleId() {
		return articleId;
	}

	public void setArticleId(Long articleId) {
		this.articleId = articleId;
	}

	public String getArticleName() {
		return articleName;
	}

	public void setArticleName(String articleName) {
		this.articleName = articleName;
	}

	public String getArticleContent() {
		return articleContent;
	}

	public void setArticleContent(String articleContent) {
		this.articleContent = articleContent;
	}

	public Date getLastEditDate() {
		return lastEditDate;
	}

	public void setLastEditDate(Date lastEditDate) {
		this.lastEditDate = lastEditDate;
	}
}


这样就可以了

展开阅读全文

没有更多推荐了,返回首页