我是java的新手。我创建了一个实体类。我想要一个字段的默认值。我尝试了@Column(name = "ProjectStatus", nullable = false,columnDefinition = "varchar(50) default 'start'")
注释但收到错误
我的实体类是
package com.ults.hrms.model;
// default package
// Generated 17 Jan, 2017 12:04:43 PM by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.ColumnDefault;
@Entity
@Table(name = "t_projectmaster", catalog = "db_hrms")
public class Projectmaster implements java.io.Serializable {
private Integer projectId;
private String projectUserIdtemp;
private String projectUserIdper;
private String projectName;
private String clentName;
private String projectDesc;
private Double projectValue;
private String projectTax;
private Date targetDate;
private Integer accountmanager;
private Integer projectManager;
private byte[] pofile;
private byte[] agreementFile;
/*@Column(name = "ProjectStatus",columnDefinition = "varchar(50) default 'ToStart'")*/
private String projectStatus;
private Boolean actvieStatus;
private Date creationDate;
private Date modifiedDate;
private Integer userId;
private String remarks;
public Projectmaster() {
}
public Projectmaster(String projectStatus) {
this.projectStatus = projectStatus;
}
public Projectmaster(String projectUserIdtemp, String projectUserIdper,
String projectName, String clentName, String projectDesc,
Double projectValue, String projectTax, Date targetDate,
Integer accountmanager, Integer projectManager, byte[] pofile,
byte[] agreementFile, String projectStatus, Boolean actvieStatus,
Date creationDate, Date modifiedDate, Integer userId, String remarks) {
this.projectUserIdtemp = projectUserIdtemp;
this.projectUserIdper = projectUserIdper;
this.projectName = projectName;
this.clentName = clentName;
this.projectDesc = projectDesc;
this.projectValue = projectValue;
this.projectTax = projectTax;
this.targetDate = targetDate;
this.accountmanager = accountmanager;
this.projectManager = projectManager;
this.pofile = pofile;
this.agreementFile = agreementFile;
this.projectStatus = projectStatus;
this.actvieStatus = actvieStatus;
this.creationDate = creationDate;
this.modifiedDate = modifiedDate;
this.userId = userId;
this.remarks = remarks;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ProjectID", unique = true, nullable = false)
public Integer getProjectId() {
return this.projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
@Column(name = "ProjectUserIDTemp", length = 50)
public String getProjectUserIdtemp() {
return this.projectUserIdtemp;
}
public void setProjectUserIdtemp(String projectUserIdtemp) {
this.projectUserIdtemp = projectUserIdtemp;
}
@Column(name = "ProjectUserIDPer", length = 50)
public String getProjectUserIdper() {
return this.projectUserIdper;
}
public void setProjectUserIdper(String projectUserIdper) {
this.projectUserIdper = projectUserIdper;
}
@Column(name = "ProjectName")
public String getProjectName() {
return this.projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
@Column(name = "ClentName", length = 100)
public String getClentName() {
return this.clentName;
}
public void setClentName(String clentName) {
this.clentName = clentName;
}
@Column(name = "ProjectDesc", length = 65535)
public String getProjectDesc() {
return this.projectDesc;
}
public void setProjectDesc(String projectDesc) {
this.projectDesc = projectDesc;
}
@Column(name = "ProjectValue", precision = 22, scale = 0)
public Double getProjectValue() {
return this.projectValue;
}
public void setProjectValue(Double projectValue) {
this.projectValue = projectValue;
}
@Column(name = "ProjectTax", length = 50)
public String getProjectTax() {
return this.projectTax;
}
public void setProjectTax(String projectTax) {
this.projectTax = projectTax;
}
@Temporal(TemporalType.DATE)
@Column(name = "TargetDate", length = 10)
public Date getTargetDate() {
return this.targetDate;
}
public void setTargetDate(Date targetDate) {
this.targetDate = targetDate;
}
@Column(name = "Accountmanager")
public Integer getAccountmanager() {
return this.accountmanager;
}
public void setAccountmanager(Integer accountmanager) {
this.accountmanager = accountmanager;
}
@Column(name = "ProjectManager")
public Integer getProjectManager() {
return this.projectManager;
}
public void setProjectManager(Integer projectManager) {
this.projectManager = projectManager;
}
@Column(name = "POFile")
public byte[] getPofile() {
return this.pofile;
}
public void setPofile(byte[] pofile) {
this.pofile = pofile;
}
@Column(name = "AgreementFile")
public byte[] getAgreementFile() {
return this.agreementFile;
}
public void setAgreementFile(byte[] agreementFile) {
this.agreementFile = agreementFile;
}
@Column(name = "ProjectStatus", nullable = false,columnDefinition = "varchar(50) default 'start'")
public String getProjectStatus() {
return this.projectStatus;
}
public void setProjectStatus(String projectStatus) {
this.projectStatus = projectStatus;
}
@Column(name = "ActvieStatus")
public Boolean getActvieStatus() {
return this.actvieStatus;
}
public void setActvieStatus(Boolean actvieStatus) {
this.actvieStatus = actvieStatus;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CreationDate",columnDefinition = "DATE DEFAULT CURRENT_DATE", length = 19)
public Date getCreationDate() {
return this.creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "ModifiedDate", length = 19)
public Date getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
@Column(name = "UserID")
public Integer getUserId() {
return this.userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
@Column(name = "Remarks", length = 65535)
public String getRemarks() {
return this.remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
}
答案 0 :(得分:2)
这对你有用,
仅在创建对象时初始化属性。
private String projectStatus = "start";