java 带有 Spring 数据 JPA 的 Spring 启动:无法提取 ResultSet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36464072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:29:32  来源:igfitidea点击:

Spring boot with Spring data JPA: could not extract ResultSet

javamysqlspringspring-mvcjpa

提问by ATEF CHAREF

I develop a Spring boot application with spring data JPA is anyone has a solution for this problem please?: My bean:

我使用 spring 数据 JPA 开发了一个 Spring 启动应用程序,请问有人有解决此问题的方法吗?:我的 bean:

@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;
}

}

}

My service is like that:

我的服务是这样的:

interface EmployeeRepository extends Repository<Employee, Long> {

Page<Employee> findAll(Pageable pageable);

Employee findByEmployeeNameAndEmployeeCin(String employeeName, String cin);

}

}

then I get this error on com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'employee0_.employee_adress' in 'field list'

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

My Database is correctly generated and its is identic to bean generated! I didnot understant really what is the problem! so please anyone can help me to resolve This? Thank you men, If you need any other informations just ask me

我的数据库已正确生成,并且与生成的 bean 相同!我真的不明白有什么问题!所以请任何人都可以帮我解决这个问题?谢谢你们,如果您需要任何其他信息,请询问我

采纳答案by Matteo Baldi

As pointed out in another answer:

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

By default Spring uses org.springframework.boot.orm.jpa.SpringNamingStrategyto 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.nameattribute 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")

默认情况下,Spring 使用 org.springframework.boot.orm.jpa.SpringNamingStrategy生成表名。这是 org.hibernate.cfg.ImprovedNamingStrategy. 该类中的 tableName 方法传递了一个源字符串值,但它不知道它是来自@Column.name属性还是从字段名称隐式生成。

改进的命名策略会将 CamelCase 转换为 SNAKE_CASE,而 EJB3NamingStrategy 只是使用未更改的表名。

如果您不想更改命名策略,您可以始终以小写形式指定列名:

@Column(name="testname")

Plus, are you sure the column is "employeeadress" and not "employeeaddress"?

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