1

I am new in java. i created a entity class. where i wanted a default value for a field. i tried @Column(name = "ProjectStatus", nullable = false,columnDefinition = "varchar(50) default 'start'") annotaions but getting errors

my entity class is

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; } } 
1
  • What kind of exception you got? Can you show exception message? Commented Jan 25, 2017 at 5:10

1 Answer 1

4

This will work for you,

Initialise the attribute while creating object only.

private String projectStatus = "start"; 
Sign up to request clarification or add additional context in comments.

5 Comments

its works for me...could you tell me why i get error use this code @Column(name = "ProjectStatus",columnDefinition = "varchar(50) default 'ToStart'")
can you try this @Column(length = 32, columnDefinition = "varchar(32) default 'ToStart'").
@luee this is due to you are giving column name in capitals and JPA expecting name in camel case format. i.e. projectStatus
its not working @Column(length = 32, columnDefinition = "varchar(32) default 'ToStart'")
ProjectStatus attribute is already created in your table so you need to clean db then try once.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.