英文:
SpringBoot 3, hibernate 6 tables not created
问题
我正在启动一个全新的Java项目,基于以下内容:
- Java 17
- Spring Boot 3.1 → 自动导入Hibernate 6.2.2 Final
- Querydsl 5.0
我使用通常的注解创建了一个表格:
- @Table
- @Entity
该对象实现了Serializable接口。
但是,当我启动应用程序时,数据库没有初始化。
显然,我在application.properties文件中设置了以下内容:
spring.jpa.hibernate.ddl-auto=update
应用程序类与模型位于同一个包中,为确保正确,我添加了@EntityScan注解并指定了根包名称,但什么也没有发生。
我没有收到任何错误消息,数据库连接已正确建立。
英文:
I'm starting a brand new java project, based on
- java 17
- spring boot 3.1 → automatically import hibernate 6.2.2 final
- querydsl 5.0
I created a table using usual annotation
- @Table
- @Entity
the object implements Serializable
but when I start the application, database is not initialized.
I obviously put in the application.properties
spring.jpa.hibernate.ddl-auto=update
Application class is on the same package of the model and to be sure I added @EntityScan with root package name, but nothing happened.
I have not any error message, db connection is correctly established
Any suggestion?
答案1
得分: 1
你已正确配置以下属性吗?可能会在创建表时引发问题。
- spring.jpa.hibernate.connection.provider_class
- spring.jpa.properties.hibernate.dialect
- spring.jpa.hibernate.ddl-auto
请检查上述内容,我认为这将解决问题。
英文:
Have you configured the below properties properly? as its maybe create an issue while creating an table.
- spring.jpa.hibernate.connection.provider_class
- spring.jpa.properties.hibernate.dialect
- spring.jpa.hibernate.ddl-auto
please check above and I think it will resolved the issue.
答案2
得分: 0
有几种可能的原因:
- 你尝试过使用以下配置来运行它吗:
spring.jpa.generate-ddl=true
-
你的实体类与带有 @EnableAutoConfiguration 注解的类位于同一包或子包中。如果不是的话,你的 Spring 应用程序将无法看到它们,因此不会在数据库中创建任何内容。
-
你的 application.properties 文件必须位于 src/main/resources 文件夹中。检查你的配置,看起来你正在使用一些 Hibernate。
英文:
There are several possible causes:
1.Did you try running it with:
spring.jpa.generate-ddl=true
2.Your entity classes are in the same or in a sub-package relative one where you have you class with @EnableAutoConfiguration. If not
then your spring app does not see them and hence will not create
anything in db
3.Your application.properties must be in src/main/resources folder. Check your config, it seems that you are using some hibernate
答案3
得分: 0
"Everything was correct, I was checking wrong db via dbeaver" 可以翻译为:一切都是正确的,我是通过dbeaver检查错误的数据库。
英文:
Everything was correct, I was checking wrong db via dbeaver
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论