Java spring boot无法在mysql数据库中生成表
我试图从Defined JPAEEntities更新数据库模式,但spring boot无法生成数据库表。 日志文件: application.properties文件:Java spring boot无法在mysql数据库中生成表,java,mysql,spring,Java,Mysql,Spring,我试图从Defined JPAEEntities更新数据库模式,但spring boot无法生成数据库表。 日志文件: application.properties文件: spring.datasource.url= jdbc:mysql://localhost:3306/banque_db spring.datasource.username= root spring.datasource.password= spring.datasource.driver-class-name= com.m
spring.datasource.url= jdbc:mysql://localhost:3306/banque_db
spring.datasource.username= root
spring.datasource.password=
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto= update
spring.jpa.show-sql= true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
客户端实体类:
@Entity(name="client")
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long code;
private String name;
private String email;
@OneToMany(mappedBy = "compte")
private Collection<Compte> comptes;
// + getters and setters
@Entity(name=“client”)
公共类客户端实现可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私有长码;
私有字符串名称;
私人字符串电子邮件;
@OneToMany(mappedBy=“compte”)
私人收藏公司;
//+能手和二传手
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring启动程序父级
2.1.0.1发布
com.Tuto
<artifactId>MaBanque</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MaBanque</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</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-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
MaBanque
0.0.1-快照
马班克
SpringBoot的演示项目
1.8
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧启动装置
org.springframework.boot
SpringBootStarterWeb
mysql
mysql连接器java
运行时
org.springframework.boot
弹簧起动试验
测验
org.springframework.boot
springbootmaven插件
您必须设置
spring.jpa.hibernate.ddl-auto=create
以创建数据库或create drop
有关更多详细信息,请参阅。第一个问题:
application.properties
文件:
spring.jpa.hibernate.ddl-auto=update
,它将不会为您创建架构。相反,它将更新现有数据库,而您当前没有该数据库spring.jpa.hibernate.ddl auto
的默认值是create drop
,但您正在覆盖它`@Entity(name="client")
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long code;
@Column
private String name;
@Column
private String email;
@OneToMany(mappedBy = "compte")
private Collection<Compte> comptes;
// + getters and setters`
`@Entity(name=“client”)
公共类客户端实现可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@纵队
@GeneratedValue(策略=GenerationType.IDENTITY)
私有长码;
@纵队
私有字符串名称;
@纵队
私人字符串电子邮件;
@OneToMany(mappedBy=“compte”)
私人收藏公司;
//+能手和二传手`
事实上,问题在于实体类不在正确的包中。
包含主类和org.entities的org.example
由于某些原因,SpringBoot没有生成表,所以当我将entity包移动到类似org.example.entities并运行应用程序时,所有成功生成的表都被删除了。
谢谢你们的帮助,我很感激:)