有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

带有Spring数据的java Spring引导JPA:无法提取结果集

我用Spring data JPA开发了一个Spring引导应用程序 有人能解决这个问题吗 我的豆子:

@Entity
@Table(name = "employee", catalog = "explorerrh")
public class Employee implements java.io.Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;


private Integer idemployee;
private String employeeName;
private String employeeLastName;
private String employeeCin;
private String employeePhone;
private String employeeAdress;
private String employeePost;
private String employeeCnss;
private String employeeCv;
private String employeePhoto;
private String employeeSalaire;

public Employee() {
}

public Employee(String employeeName, String employeeLastName,
        String employeeCin, String employeePhone, String employeeAdress,
        String employeePost, String employeeCnss, String employeeCv,
        String employeePhoto, String employeeSalaire) {
    this.employeeName = employeeName;
    this.employeeLastName = employeeLastName;
    this.employeeCin = employeeCin;
    this.employeePhone = employeePhone;
    this.employeeAdress = employeeAdress;
    this.employeePost = employeePost;
    this.employeeCnss = employeeCnss;
    this.employeeCv = employeeCv;
    this.employeePhoto = employeePhoto;
    this.employeeSalaire = employeeSalaire;
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "idemployee", unique = true, nullable = false)
public Integer getIdemployee() {
    return this.idemployee;
}

public void setIdemployee(Integer idemployee) {
    this.idemployee = idemployee;
}

@Column(name = "employeeName", length = 45)
public String getEmployeeName() {
    return this.employeeName;
}

public void setEmployeeName(String employeeName) {
    this.employeeName = employeeName;
}

@Column(name = "employeeLastName", length = 45)
public String getEmployeeLastName() {
    return this.employeeLastName;
}

public void setEmployeeLastName(String employeeLastName) {
    this.employeeLastName = employeeLastName;
}

@Column(name = "employeeCIN", length = 45)
public String getEmployeeCin() {
    return this.employeeCin;
}

public void setEmployeeCin(String employeeCin) {
    this.employeeCin = employeeCin;
}

@Column(name = "employeePhone", length = 45)
public String getEmployeePhone() {
    return this.employeePhone;
}

public void setEmployeePhone(String employeePhone) {
    this.employeePhone = employeePhone;
}

@Column(name = "employeeAdress", length = 45)
public String getEmployeeAdress() {
    return this.employeeAdress;
}

public void setEmployeeAdress(String employeeAdress) {
    this.employeeAdress = employeeAdress;
}

@Column(name = "employeePost", length = 45)
public String getEmployeePost() {
    return this.employeePost;
}

public void setEmployeePost(String employeePost) {
    this.employeePost = employeePost;
}

@Column(name = "employeeCNSS", length = 45)
public String getEmployeeCnss() {
    return this.employeeCnss;
}

public void setEmployeeCnss(String employeeCnss) {
    this.employeeCnss = employeeCnss;
}

@Column(name = "employeeCV", length = 45)
public String getEmployeeCv() {
    return this.employeeCv;
}

public void setEmployeeCv(String employeeCv) {
    this.employeeCv = employeeCv;
}

@Column(name = "employeePhoto", length = 45)
public String getEmployeePhoto() {
    return this.employeePhoto;
}

public void setEmployeePhoto(String employeePhoto) {
    this.employeePhoto = employeePhoto;
}

@Column(name = "employeeSalaire", length = 45)
public String getEmployeeSalaire() {
    return this.employeeSalaire;
}

public void setEmployeeSalaire(String employeeSalaire) {
    this.employeeSalaire = employeeSalaire;
}

}

我的服务是这样的:

interface EmployeeRepository extends Repository<Employee, Long> {

Page<Employee> findAll(Pageable pageable);

Employee findByEmployeeNameAndEmployeeCin(String employeeName, String cin);

}

然后我在com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'employee0_.employee_adress' in 'field list'上得到了这个错误

我的数据库是正确生成的,它与生成的bean相同! 我不明白到底是什么问题!有谁能帮我解决这个问题吗? 谢谢你们,如果你们需要任何其他信息,尽管问我


共 (1) 个答案

  1. # 1 楼答案

    正如另一篇文章所指出的:

    By default Spring uses org.springframework.boot.orm.jpa.SpringNamingStrategy to generate table names. This is a very thin extension of org.hibernate.cfg.ImprovedNamingStrategy. The tableName method in that class is passed a source String value but it is unaware if it comes from a @Column.name attribute or if it has been implicitly generated from the field name.

    The ImprovedNamingStrategy will convert CamelCase to SNAKE_CASE where as the EJB3NamingStrategy just uses the table name unchanged.

    If you don't want to change the naming strategy you could always just specify your column name in lowercase:

    @Column(name="testname")

    另外,你确定该栏是“employeeaddress”而不是“employeeaddress”吗