UniqueConstraint没有反映到表中

时间:2017-04-03 07:54:58

标签: hibernate nhibernate-mapping

我要求email_id是唯一的,所以我将它保持为唯一的约束。但这些变化并未反映在DDL中。我在另一个表compliance_user中做了同样的事情,它在那里工作正常。但为什么不在注册表中发生呢?

registration.java

 package com.uforic.compliance.spring.model;

 import java.util.Date;

 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 import javax.persistence.Transient;
 import javax.persistence.UniqueConstraint;

@Entity
@Table(name="registration",uniqueConstraints = {@UniqueConstraint(columnNames ="email_id")})
public class Registration {

@Id
@Column(name="reg_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int regId;

@Column(name="first_name")
private String firstName;

@Column(name="last_name")
private String lastName;

@Column(name="email_id")
private String emailId;

@Column(name="password")
private String password;

@Column(name="confirm_password")
private String confirmPassword;

@Column(name="ref_email_id")
private String RefEmailId;

@Column(name="company_name")
private String companyName;

@Column(name="role_id_fk")
private int roleMaster;

@Transient
private String compliance;

@Transient
private String year;

@Transient
private Integer accessRights;

@Transient
private Integer userGroupId;

public int getRegId() {
    return regId;
}

public void setRegId(int regId) {
    this.regId = regId;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getEmailId() {
    return emailId;
}

public void setEmailId(String emailId) {
    this.emailId = emailId;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getConfirmPassword() {
    return confirmPassword;
}

public void setConfirmPassword(String confirmPassword) {
    this.confirmPassword = confirmPassword;
}

public String getRefEmailId() {
    return RefEmailId;
}

public void setRefEmailId(String refEmailId) {
    RefEmailId = refEmailId;
}

public String getCompanyName() {
    return companyName;
}

public void setCompanyName(String companyName) {
    this.companyName = companyName;
}

public int getRoleMaster() {
    return roleMaster;
}

public void setRoleMaster(int roleMaster) {
    this.roleMaster = roleMaster;
}

public String getCompliance() {
    return compliance;
}

public void setCompliance(String compliance) {
    this.compliance = compliance;
}

public String getYear() {
    return year;
}

public void setYear(String year) {
    this.year = year;
}

public Integer getAccessRights() {
    return accessRights;
}

public void setAccessRights(Integer accessRights) {
    this.accessRights = accessRights;
}

public Integer getUserGroupId() {
    return userGroupId;
}

public void setUserGroupId(Integer userGroupId) {
    this.userGroupId = userGroupId;
}

@Override
public String toString() {
    return "Registration [regId=" + regId + ", firstName=" + firstName + ", lastName=" + lastName + ", emailId="
            + emailId + ", password=" + password + ", confirmPassword=" + confirmPassword + ", RefEmailId="
            + RefEmailId + ", companyName=" + companyName + ", roleMaster=" + roleMaster + "]";
}

}

注册DDL

  CREATE TABLE registration
(
reg_id serial NOT NULL,
ref_email_id character varying(255),
company_name character varying(255),
confirm_password character varying(255),
email_id character varying(255),
first_name character varying(255),
last_name character varying(255),
password character varying(255),
role_id_fk integer,
CONSTRAINT registration_pkey PRIMARY KEY (reg_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE registration
OWNER TO compliance;

1 个答案:

答案 0 :(得分:0)

重新生成DDL后它起作用