使用 Spring 数据 JPA 进行 Spring 启动:无法提取结果集

问题描述 投票:0回答:3

我使用 Spring Data JPA 开发 Spring Boot 应用程序 请问有人有这个问题的解决方案吗?: 我的豆子:

@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 相同! 我真的不明白是什么问题!所以请任何人都可以帮我解决这个问题吗? 谢谢各位,如果您需要任何其他信息,请问我

java mysql spring spring-mvc jpa
3个回答
4
投票

正如另一个答案中指出的:

Spring 默认使用

org.springframework.boot.orm.jpa.SpringNamingStrategy
生成 表名。这是一个非常薄的扩展
org.hibernate.cfg.ImprovedNamingStrategy
。其中的 tableName 方法 类被传递了一个源字符串值,但它不知道它是否到来 来自
@Column.name
属性或者它是隐式生成的 从字段名称。

ImprovedNamingStrategy 会将 CamelCase 转换为 SNAKE_CASE,其中 因为 EJB3NamingStrategy 只是使用未更改的表名称。

如果您不想更改命名策略,您可以随时更改 以小写形式指定您的列名称:

@Column(name="testname")

另外,您确定该列是“employeeadress”而不是“employeeaddress”吗?


1
投票

确保

@Column(name="table_name")
的所有名称均按照数据库列名称正确给出。


0
投票

我的错误(字段列表) es porque esperas recibir un (Employee findByEmployeeNameAndEmployeeCin(String employeeName, String cin)) y la Consulta retorna una lista informa con List findByEmployeeNameAndEmployeeCin(String employeeName, String cin);

© www.soinside.com 2019 - 2024. All rights reserved.