在尝试在JPA

时间:2016-03-01 05:11:44

标签: mysql jpa

我正在尝试在User和UserIdentification之间建立OneToMany关系,其中要针对用户配置文件保存许多标识记录。我试图将UserIdentification表中的mu_profile_id保存为名为'mui_profile_id'的外键。

请找到下表结构。 用户标识详细信息列表存储在用户对照列表UserIdentification实体。

CREATE TABLE a2b_mstr_user(   mu_id int(15)NOT NULL AUTO_INCREMENT,   mu_profile_id varchar(30)NOT NULL,   mu_user_id varchar(30)NOT NULL,   mu_password varchar(30)NOT NULL,   mu_first_name varchar(50)NOT NULL,   mu_last_name varchar(50)NOT NULL,   mu_gender varchar(1)NOT NULL,   mu_nationality varchar(30)NOT NULL,   mu_date_of_birth日期非空,   mu_place_of_birth varchar(30)DEFAULT NULL,   mu_notes小文字,   mu_status tinyint(4)DEFAULT NULL,   mu_locked tinyint(4)DEFAULT NULL,   mu_unsuc_log_attmpts int(1)DEFAULT NULL,   PRIMARY KEY(mu_id),   KEY last_name_indmu_last_name),   KEY profile_id_indmu_profile_id) )ENGINE = InnoDB

用户识别表

CREATE TABLE a2b_mstr_user_identification(   mui_identfcn_id int(15)NOT NULL AUTO_INCREMENT,   mui_profile_id varchar(30)NOT NULL,   mui_document_type varchar(30)NOT NULL,   mui_document_category varchar(30)DEFAULT NULL,   mui_document_no varchar(50)NOT NULL,   mui_country varchar(30)DEFAULT NULL,   mui_state varchar(30)DEFAULT NULL,   mui_valid_from日期DEFAULT NULL,   mui_valid_to日期DEFAULT NULL,   mui_status varchar(10)NOT NULL DEFAULT'Y'COMMENT'确定文档是否有效。 ''Y''如果''有效'''''''',如果没有激活。',   PRIMARY KEY(mui_identfcn_id),   独特的钥匙DOCUMENT_NO_INDmui_document_no),   KEY USER_IDENTIFICATION_FKmui_profile_id),   CONSTRAINT USER_IDENTIFICATION_FK FOREIGN KEY(mui_profile_id)引用a2b_mstr_usermu_profile_id)ON DELETE CASCADE ON UPDATE CASCADE )ENGINE = InnoDB

和User的实体。

@Entity
@Table(name="A2B_MSTR_USER")
public class User extends BaseEntity{

    @Column(name="mu_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected String muId;

    @Column(name="mu_profile_id")
    protected String profileId;

    @Column(name="mu_user_id")
    @NotEmpty
    protected String userId;

    @Column(name="mu_password")
    protected String password;

    @Column(name="mu_first_name")
    @NotEmpty
    protected String firstName;

    @Column(name="mu_last_name")
    @NotEmpty
    protected String lastName;

    @Column(name="mu_gender")
    @NotEmpty
    protected String gender;

    @Column(name="mu_nationality")
    @NotEmpty
    protected String nationality;

    @Column(name="mu_date_of_birth")
    protected Date dateOfBirth;

    @Column(name="mu_place_of_birth")
    protected String placeOfBirth;

    @Column(name="mu_notes")
    protected String notes;

    @Column(name="mu_status")
    protected Short status;

    @Column(name="mu_locked")
    protected boolean isLocked;

    @Column(name="mu_unsuc_log_attmpts")
    protected int unSucLogonAttmpts;

    @OneToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL,mappedBy="user")
    protected UserContact userContact;

    @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL,mappedBy="user")
    protected List<UserAttachment>  userAttachments;

    @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name="mui_profile_id",insertable=true,updatable=true)
    protected List<UserIdentification>  userIdentificationDetails;

    @PrePersist
    protected void prePersist(){
        if(getProfileId()==null){
        setProfileId(new IdGenerator(10).nextString().toUpperCase());
        }
    }

    public String getMuId() {
        return muId;
    }

    public void setMuId(String muId) {
        this.muId = muId;
    }

    public String getProfileId() {
        return profileId;
    }

    public void setProfileId(String profileId) {
        this.profileId = profileId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPassword() {
        return password;
    }

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

    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 getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getNationality() {
        return nationality;
    }

    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getPlaceOfBirth() {
        return placeOfBirth;
    }

    public void setPlaceOfBirth(String placeOfBirth) {
        this.placeOfBirth = placeOfBirth;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }


    public UserContact getUserContact() {
        return userContact;
    }

    public void setUserContact(UserContact userContact) {
        this.userContact = userContact;

    }

    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public boolean isLocked() {
        return isLocked;
    }

    public void setLocked(boolean isLocked) {
        this.isLocked = isLocked;
    }

    public int getUnSucLogonAttmpts() {
        return unSucLogonAttmpts;
    }

    public void setUnSucLogonAttmpts(int unSucLogonAttmpts) {
        this.unSucLogonAttmpts = unSucLogonAttmpts;
    }

    public List<UserAttachment> getUserAttachments() {
        return userAttachments;
    }

    public void setUserAttachments(List<UserAttachment> userAttachments) {
        this.userAttachments = userAttachments;
    }


    public List<UserIdentification> getUserIdentificationDetails() {
        return userIdentificationDetails;
    }

    public void setUserIdentificationDetails(ArrayList<UserIdentification> userIdentificationDetails) {
        this.userIdentificationDetails = userIdentificationDetails;
    }


}

UserIdentification的实体如下。

@Entity
@Table(name="A2B_MSTR_USER_IDENTIFICATION")
public class UserIdentification extends BaseEntity {

    @Column(name="mui_identfcn_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Integer identificationId;

    @Column(name="mui_document_type")
    protected String documentType;

    @Column(name="mui_document_category")
    protected String documentCategory;

    @Column(name="mui_document_no")
    protected String documentNo;

    @Column(name="mui_country")
    protected String country;

    @Column(name="mui_state")
    protected String state;

    @Column(name="mui_valid_from")
    protected Date validFrom;

    @Column(name="mui_valid_to")
    protected Date validTo;

    @Column(name="mui_status")
    protected String status;


    public Integer getIdentificationId() {
        return identificationId;
    }

    public void setIdentificationId(Integer identificationId) {
        this.identificationId = identificationId;
    }

    public String getDocumentType() {
        return documentType;
    }

    public void setDocumentType(String documentType) {
        this.documentType = documentType;
    }

    public String getDocumentCategory() {
        return documentCategory;
    }

    public void setDocumentCategory(String documentCategory) {
        this.documentCategory = documentCategory;
    }

    public String getDocumentNo() {
        return documentNo;
    }

    public void setDocumentNo(String documentNo) {
        this.documentNo = documentNo;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Date getValidFrom() {
        return validFrom;
    }

    public void setValidFrom(Date validFrom) {
        this.validFrom = validFrom;
    }

    public Date getValidTo() {
        return validTo;
    }

    public void setValidTo(Date validTo) {
        this.validTo = validTo;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }



    @Override
    public String toString() {
        return "UserIdentification [identificationId=" + identificationId + ", documentType=" + documentType
                + ", documentCategory=" + documentCategory + ", documentNo=" + documentNo + ", country=" + country
                + ", state=" + state + ", validFrom=" + validFrom + ", validTo=" + validTo + ", status=" + status
                + ", user=" + "]";
    }



}

当我尝试使用JPA保存它时,我收到错误引起:java.sql.SQLException:字段'mui_profile_id'没有默认值。

0 个答案:

没有答案