英文:
Empty DB without generated entities with Spring Boot
问题
我尝试了很多次在我的数据库中创建表格。但是什么都没有发生。我尝试了与这个问题相关的所有方法,包括在 Stack Overflow 上找到的方法和其他所有方法。
我真的需要你的帮助,因为我无法继续我的项目。直到现在,我都是按照相同的方式从我的 POJO 类开始创建带有实体的数据库,但是今天却不起作用。我真的不明白。
以下是我代码中到目前为止的所有内容。
**项目结构:**
shop
.idea
.mvn
src
main
java
shop
model
ServletInitializer
ShopApplication
resources
test
target
.gitignore
HELP.md
mvnw
mvnw.cmd
pom.xml
shop.iml
**应用程序属性:**
数据源属性
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/shop_db?createDatabaseIfNotExist=true&
spring.datasource.username = root
spring.datasource.password = 12345
JPA 属性
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.format_sql = TRUE
spring.jpa.hibernate.ddl-auto = update
spring.jpa.generate-ddl = true
spring.jpa.show-sql= true
日志级别
禁用默认的日志记录器
logging.level.org = WARN
logging.level.blog = WARN
显示带有参数绑定的 SQL
logging.level.org.hibernate.SQL = DEBUG
logging.level.org.hibernate.type.descriptor = TRACE
**我的 POM 文件**
```xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/>
<!-- 从仓库中查找父项目 -->
</parent>
<groupId>com.example</groupId>
<artifactId>shop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>com.example.shop</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
非常感谢你
<details>
<summary>英文:</summary>
Many many times I tried to create tables in my DB. But anything has happened. I tried everything which is connected with this issue, from Stack overflow and everything else.
I really need you for your help, because I can not continue with my project. Until now I started with my POJO classes to create a database with the entity in the same way, but today does not work. And I really do not understand.
Here is everything from my code up to now.
**Project structure:**
shop
.idea
.mvn
src
main
java
shop
model
ServletInitializer
ShopApplication
resources
test
target
.gitignore
HELP.md
mvnw
mvnw.cmd
pom.xml
shop.iml ```
Application properties:
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/shop_db?createDatabaseIfNotExist=true&amp
spring.datasource.username = root
spring.datasource.password = 12345
#JPA Properties
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.format_sql = TRUE
spring.jpa.hibernate.ddl-auto = update
spring.jpa.generate-ddl = true
spring.jpa.show-sql= true
###Logging Levels
# Disable the default loggers
logging.level.org = WARN
logging.level.blog = WARN
#Show SQL executed with parameter bindings
logging.level.org.hibernate.SQL = DEBUG
logging.level.org.hibernate.type.descriptor = TRACE
My POM.file
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>shop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>com.example.shop</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> ```
Thank you very much :)
</details>
# 答案1
**得分**: 1
我已找到关于这个问题的决策。实体之间的关系是错误的。
我希望这个决策对其他人有所帮助。
<details>
<summary>英文:</summary>
I have found the decision about the problem. It has been the wrong relation between entities.
I hope that this decision will be useful for somebody else.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论