我做了一个迷你Spring Boot 项目。我的目标是将表迁移到数据库。但无法将表迁移到数据库
我在终端控制台中没有任何错误,但无法迁移表
这些都是我在pom.xml中的依赖项,我添加了数据jpa和mysql连接器
<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-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>
<version>8.0.30</version>
</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>
</project>
这是应用程序.propreties我成功地链接了我的数据库
spring.datasource.url=jdbc:mysql://localhost:3306/spring_test?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl.auto=create
hibernate.dialect= org.hibernate.dialect.MySQL5Dialect
这是我的实体应该迁移到数据库
package com.learn.demo.Model;
import jakarta.persistence.*;
@Entity
@Table(name = "POST")
public class Post {
@Id
@GeneratedValue()
private long id;
@Column()
private String name;
@Column(unique = true)
private long code;
@Column()
private int views;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public int getViews() {
return views;
}
public void setViews(int views) {
this.views = views;
}
}
这是日志
2023-07-02T11:30:10.017+01:00 INFO 28904 --- [ restartedMain] com.learn.demo.DemoApplication : Starting DemoApplication using Java 17.0.7 with PID 28904 (C:\Users\Kessemtini\Desktop\projects\demo\target\classes started by Kessemtini in C:\Users\Kessemtini\Desktop\projects\demo)
2023-07-02T11:30:10.019+01:00 INFO 28904 --- [ restartedMain] com.learn.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2023-07-02T11:30:10.087+01:00 INFO 28904 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-07-02T11:30:10.087+01:00 INFO 28904 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-07-02T11:30:10.826+01:00 INFO 28904 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-07-02T11:30:10.851+01:00 INFO 28904 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 17 ms. Found 0 JPA repository interfaces.
2023-07-02T11:30:11.688+01:00 INFO 28904 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-07-02T11:30:11.698+01:00 INFO 28904 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-07-02T11:30:11.698+01:00 INFO 28904 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.10]
2023-07-02T11:30:11.761+01:00 INFO 28904 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-07-02T11:30:11.763+01:00 INFO 28904 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1674 ms
2023-07-02T11:30:11.925+01:00 INFO 28904 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-07-02T11:30:12.094+01:00 INFO 28904 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@189b0459
2023-07-02T11:30:12.096+01:00 INFO 28904 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-07-02T11:30:12.146+01:00 INFO 28904 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-07-02T11:30:12.209+01:00 INFO 28904 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.2.5.Final
2023-07-02T11:30:12.211+01:00 INFO 28904 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000406: Using bytecode reflection optimizer
2023-07-02T11:30:12.350+01:00 INFO 28904 --- [ restartedMain] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy
2023-07-02T11:30:12.498+01:00 INFO 28904 --- [ restartedMain] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-07-02T11:30:12.772+01:00 INFO 28904 --- [ restartedMain] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy
2023-07-02T11:30:13.315+01:00 INFO 28904 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-07-02T11:30:13.317+01:00 INFO 28904 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-07-02T11:30:13.705+01:00 INFO 28904 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-07-02T11:30:13.733+01:00 INFO 28904 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-07-02T11:30:13.742+01:00 INFO 28904 --- [ restartedMain] com.learn.demo.DemoApplication : Started DemoApplication in 4.168 seconds (process running for 4.683)
2023-07-02T12:07:14.601+01:00 WARN 28904 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=30m39s83ms799µs400ns).
这是主应用程序
package com.learn.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
1条答案
按热度按时间ctehm74n1#
使用此实体类
}