Spring Boot Hibernate JPA表不存在错误排查求助
Hey there! Let's get to the bottom of why your Hibernate isn't auto-creating the table and resolve that frustrating error. The most obvious issue here is a typo in your application.properties configuration—let's break down the fixes and checks step by step.
1. Critical Configuration Typo Fix
Your application.properties has a misspelled property that's preventing Hibernate from auto-generating the table:
Original (Incorrect) Line:
spring.jpa.hibernate.dll-auto = create
This should be ddl-auto (short for Data Definition Language), not dll-auto (which refers to Dynamic Link Libraries). Hibernate ignores misspelled properties, so it never gets the instruction to create tables.
Corrected Line:
spring.jpa.hibernate.ddl-auto = create
2. Additional Checks to Ensure Success
Even after fixing the typo, let's verify a few more things to rule out other issues:
- Confirm the target database exists: Hibernate won't automatically create the
db_studentdatabase itself—you need to manually create it in MySQL first. Log into your MySQL instance and run:CREATE DATABASE db_student; - Validate database connection details:
- Double-check the port: Your URL uses
3303, but MySQL's default port is3306. Make sure your MySQL service is actually running on3303, or adjust the URL to use3306if that's correct. - Ensure the
springuseraccount has permissions: Verify that the userspringuserhasCREATE,INSERT, andSELECTpermissions on thedb_studentdatabase. You can grant these with:GRANT ALL PRIVILEGES ON db_student.* TO 'springuser'@'localhost'; FLUSH PRIVILEGES;
- Double-check the port: Your URL uses
- Verify entity annotations: Your
Studentclass is correctly annotated with@Entityand@Table(name = "students_table"), so Hibernate should recognize it as a table to generate. No issues here, but just ensure the class is in a package that's scanned by Spring Boot (yourApplication.javais inFirstPackage, and all other classes are in the same package, so component scanning should work fine).
3. Test the Fix
After making these changes, restart your Spring Boot application. When it starts up, Hibernate will automatically create the students_table in the db_student database. You can then test your /main/add and /main/all endpoints without the "Table does not exist" error.
Note for Production
While create is great for development (it recreates tables on every startup), avoid using it in production. Instead, use update (to modify existing tables without dropping data) or none (to disable auto-DDL entirely and manage schema changes manually).
内容的提问来源于stack exchange,提问作者Ayushi Singh

