SpringBoot 3,hibernate 6 表未创建

huangapple go评论59阅读模式
英文:

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

SpringBoot 3,hibernate 6 表未创建

Any suggestion?

答案1

得分: 1

你已正确配置以下属性吗?可能会在创建表时引发问题。

  1. spring.jpa.hibernate.connection.provider_class
  2. spring.jpa.properties.hibernate.dialect
  3. spring.jpa.hibernate.ddl-auto

请检查上述内容,我认为这将解决问题。

英文:

Have you configured the below properties properly? as its maybe create an issue while creating an table.

  1. spring.jpa.hibernate.connection.provider_class
  2. spring.jpa.properties.hibernate.dialect
  3. spring.jpa.hibernate.ddl-auto

please check above and I think it will resolved the issue.

答案2

得分: 0

有几种可能的原因:

  1. 你尝试过使用以下配置来运行它吗:

spring.jpa.generate-ddl=true

  1. 你的实体类与带有 @EnableAutoConfiguration 注解的类位于同一包或子包中。如果不是的话,你的 Spring 应用程序将无法看到它们,因此不会在数据库中创建任何内容。

  2. 你的 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

huangapple
  • 本文由 发表于 2023年5月29日 20:07:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357237.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定