You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Hibernate JPA表不存在错误排查求助

Fixing "Table does not exist" Error in Spring Boot Hibernate POC

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_student database 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 is 3306. Make sure your MySQL service is actually running on 3303, or adjust the URL to use 3306 if that's correct.
    • Ensure the springuser account has permissions: Verify that the user springuser has CREATE, INSERT, and SELECT permissions on the db_student database. You can grant these with:
      GRANT ALL PRIVILEGES ON db_student.* TO 'springuser'@'localhost';
      FLUSH PRIVILEGES;
      
  • Verify entity annotations: Your Student class is correctly annotated with @Entity and @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 (your Application.java is in FirstPackage, 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 10:13:14