gpt4 book ai didi

java - Spring MVC JPA 异常 org.hibernate.exception.SQLGrammarException

转载 作者:行者123 更新时间:2023-11-29 12:34:17 25 4
gpt4 key购买 nike

我是 Spring JPA 的新手。我现在正在学习。我在尝试将数据插入 mysql 数据库时遇到奇怪的错误。

我确保我的表和数据库设置正确,与我的相同

mysql> show columns in empolyee in test;


| Field | Type | Null | Key | Default | Extra |

| id | int(6) | NO | PRI | NULL | auto_increment |
eid | int(6) | YES | | NULL | |
| name | varchar(40) | NO | | NULL | |
| role | varchar(20) | YES | | NULL | |

我的实体类:-

      @Entity
public class Employee extends AbstractPersistable<Long> {

private int eid;
private String name;
private String role;

public Employee(){

}

public Employee(int aeid, String aname, String arole){
eid=aeid;
name = aname;
role = arole;
}
}

错误:-

 HTTP Status 500 - Request processing failed; nested exception is  org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.SQLGrammarException: Table 'test.employee' doesn't exist; 
nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException:
Table 'test.employee' doesn't exist

最佳答案

您在数据库中的表名为 empolyee

@Entity
public class Employee extends AbstractPersistable<Long>

这里您没有指定@Table注释,因此JPA将采用表名作为类名,即您的数据库中不存在的Employee。因此改变这个

@Entity
@Table(name="empolyee") //this exists in database
public class Employee extends AbstractPersistable<Long>

关于java - Spring MVC JPA 异常 org.hibernate.exception.SQLGrammarException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27034113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com