gpt4 book ai didi

java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Table doesn't exist

转载 作者:可可西里 更新时间:2023-11-01 08:26:37 24 4
gpt4 key购买 nike

当我在 http://localhost:8080/api/projects 访问它时,我猜它连接到我的 MySQL 数据库,我有一个表 PROJECTS(ID, TITLE),但显示以下错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'bugtrackerdb.projects' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_40]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_40]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_40]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]

实体

@Entity
@Table(name = "PROJECTS")
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class Project implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "TITLE")
private String title;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<Module> modules;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<Bug> bugs;

资源

@Component
@Path("/projects")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ProjectsResource {

@Autowired
ProjectService projectService;

@GET
public List<Project> getProjects() {
return projectService.getAllProjects();
}

@POST
public Project createProject(Project project) {
return projectService.createProject(project);
}
}

存储库

public interface ProjectRepository extends JpaRepository<Project, Long> {

}

hibernate 属性

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
hibernate.format_sql=true
hibernate.show_sql=true
entitymanager.packages.to.scan=intuitio.kickstart.jersey.domain
hibernate.auto=create

连接属性

db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://127.0.0.1:3306/bugtrackerdb
db.username=root
db.password=pass

最佳答案

您应该使用 hibernate.hbm2ddl.auto 而不是 hibernate.auto 来创建数据库。

关于java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Table doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34728570/

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