com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table doesn't exist
11,232
You should use hibernate.hbm2ddl.auto
not hibernate.auto
to create a database.
Author by
Nicolae Focsa
Updated on June 09, 2022Comments
-
Nicolae Focsa almost 2 years
When I access it at http://localhost:8080/api/projects, I guess that it connects to my MySQL database, where I have a table PROJECTS(ID, TITLE), but shows following error
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
@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;
Resource
@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); } }
Repository
public interface ProjectRepository extends JpaRepository<Project, Long> { }
Hibernate properties
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
Connection properties
db.driver=com.mysql.jdbc.Driver db.url=jdbc:mysql://127.0.0.1:3306/bugtrackerdb db.username=root db.password=pass
-
Nicolae Focsa over 8 yearsThank you for answer. In fact I have an ApplicationConfig class where I set dataSource and hibernate properties extracted from a *.properties file and I didn't write "hibernate.hbm2ddl.auto" properly in that class.
-
v.ladynev over 8 years@NicolaeFocsa You are welcome. You can refer HibernateSessionFactory.Builder as an example of configuration utility class.
-
FuSsA about 8 years@v.ladynev im using hibernate.hbm2ddl.auto and still got the same error ! :3
-
v.ladynev about 8 years@FuSsA Please, ask your own question and provide your configuration.
-
FuSsA about 8 years@v.ladynev link