java - 即使在使用 @AttributeOverrides 更改属性名称后,我仍然收到重复列错误
问题描述
package com.hashedin.employeemanagementsystem.entities;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Data
@Table(name="employee")
@Entity(name="User")
public class User{
public User(){
this.individual = new Individual();
this.workExperience = null;
this.experienceInMonths = null;
this.jobRole = null;
this.primaryContact = null;
this.secondaryContact = null;
this.employeeID = null;
this.joiningDate = null;
this.employeeCategory = null;
this.exitDate = null;
this.educationDetails = null;
}
@Id
//Employee 4 digit ID
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="employee_id")
private Long empID;
//employee ID Code
@Column(name = "employee_code_id")
private String employeeID;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="first_name", column = @Column(name="employee_first_name")),
@AttributeOverride(name="last_name", column = @Column(name="employee_last_name")),
@AttributeOverride(name="email", column = @Column(name="employee_email")),
@AttributeOverride(name="phone", column = @Column(name="employee_phone")),
})
private Individual individual;
//Primary and Secondary Contacts
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "email", column = @Column(name = "primary_contact_email")),
@AttributeOverride(name = "Individual.first_name", column = @Column(name = "primary_contact_first_name")),
@AttributeOverride(name = "last_name", column = @Column(name = "primary_contact_last_name")),
@AttributeOverride(name = "phone", column = @Column(name = "primary_contact_phone"))
})
private Individual primaryContact;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="email", column = @Column(name="secondary_contact_email")),
@AttributeOverride(name="first_name", column=@Column(name="secondary_contact_first_name")),
@AttributeOverride(name="last_name", column=@Column(name="secondary_contact_last_name")),
@AttributeOverride(name="phone", column=@Column(name="secondary_contact_phone"))
})
private Individual secondaryContact;
//jobRole
@Embedded
private JobRole jobRole;
//joining date and exit date (mentioned for Fixed Employees / probation period)
@Column(name="joining_date")
private Date joiningDate;
@Column(name="exit_date")
private Date exitDate;
//category, experience and highest degree
@OneToOne(cascade = CascadeType.ALL)
private Education educationDetails;
@Column(name="employee_category")
private String employeeCategory;
@Column(name="total_experience")
private Integer experienceInMonths;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="employee_id")
private List<Employment> workExperience;
public User(String firstName, String lastName, Location location, String email, String phone, String employeeID, Individual primaryContact, Individual secondaryContact, Date joiningDate, String employeeCategory, Date exitDate, Integer experience, Education educationDetails, JobRole jobRole, List<Employment> exp) {
this.individual = new Individual(firstName, lastName, location, email, phone);
this.workExperience = exp;
this.experienceInMonths = experience;
this.jobRole = jobRole;
this.primaryContact = primaryContact;
this.secondaryContact = secondaryContact;
this.employeeID = employeeID;
this.joiningDate = joiningDate;
this.employeeCategory = employeeCategory;
this.exitDate = exitDate;
this.educationDetails = educationDetails;
}
public Individual getIndividual() {
return individual;
}
public void setIndividual(Individual individual) {
this.individual = individual;
}
public Long getEmpID() {
return empID;
}
public void setEmpID(Long empID) {
this.empID = empID;
}
public Integer getExperienceInMonths() {
return experienceInMonths;
}
public void setExperienceInMonths(Integer experienceInMonths) {
this.experienceInMonths = experienceInMonths;
}
public List<Employment> getWorkExperience() {
return workExperience;
}
public void setWorkExperience(List<Employment> workExperience) {
this.workExperience = workExperience;
}
public JobRole getJobRole() {
return jobRole;
}
public void setJobRole(JobRole jobRole) {
this.jobRole = jobRole;
}
public Education getEducationDetails() {
return educationDetails;
}
public void setEducationDetails(Education educationDetails) {
this.educationDetails = educationDetails;
}
public Integer getExperience() {
return experienceInMonths;
}
public void setExperience(Integer experience) {
this.experienceInMonths = experience;
}
public Date getExitDate() {
return exitDate;
}
public void setExitDate(Date exitDate) {
this.exitDate = exitDate;
}
public String getEmployeeCategory() {
return employeeCategory;
}
public void setEmployeeCategory(String employeeCategory) {
this.employeeCategory = employeeCategory;
}
public String getEmployeeID() {
return employeeID;
}
public void setEmployeeID(String employeeID) {
this.employeeID = employeeID;
}
public Date getJoiningDate() {
return joiningDate;
}
public void setJoiningDate(Date joiningDate) {
this.joiningDate = joiningDate;
}
public Individual getPrimaryContact() {
return primaryContact;
}
public void setPrimaryContact(Individual primaryContact) {
this.primaryContact = primaryContact;
}
public Individual getSecondaryContact() {
return secondaryContact;
}
public void setSecondaryContact(Individual secondaryContact) {
this.secondaryContact = secondaryContact;
}
@Override
public String toString() {
return "User{" +
"empID=" + empID +
", employeeID='" + employeeID + '\'' +
", individual=" + individual.toString() +
", primaryContact=" + primaryContact +
", secondaryContact=" + secondaryContact +
", jobRole=" + jobRole +
", joiningDate=" + joiningDate +
", exitDate=" + exitDate +
", educationDetails=" + educationDetails +
", employeeCategory='" + employeeCategory + '\'' +
", experienceInMonths=" + experienceInMonths +
", workExperience=" + workExperience +
'}';
}
}
仍然出现此错误,请帮助:
org.springframework.beans.factory.BeanCreationException:在类路径资源[org/springframework/boo t/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]中定义名称为“entityManagerFactory”的bean创建错误:调用init方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; 嵌套异常是 org.hibernate.MappingException:实体映射中的重复列:com.hashedin.emplo yeemanagementsystem.entities.User 列:org.springframework 的电子邮件(应使用 insert="false" update="false" 映射)。 beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5 .3.5.jar:5.3.5]
这就是我的个人课程的样子:
package com.hashedin.employeemanagementsystem.entities;
import javax.persistence.*;
import java.lang.annotation.Target;
@Embeddable
public class Individual {
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@Embedded
private Location location;
@Column(name="email")
private String email;
@Column(name="phone")
private String phone;
public Individual(){
this.firstName="";
this.lastName="";
this.location=null;
this.email=null;
this.phone=null;
}
public Individual(String firstName, String lastName, Location location, String email, String phone) {
this.firstName = firstName;
this.lastName = lastName;
this.location = location;
this.email = email;
this.phone = phone;
}
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 Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "Individual{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", location=" + location +
", email='" + email + '\'' +
", phone='" + phone + '\'' +
'}';
}
}