当我在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
答案 0 :(得分:2)
您应该使用hibernate.hbm2ddl.auto
而不是hibernate.auto
来创建数据库。