我的物體類看起來像這樣
Person.java
package com.poc.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Person {
//properties
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String fName;
private String lName;
public Person() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
}
當我運行 Spring Boot 應用程式時,它運行良好,但沒有在資料庫中創建表
我的應用程式檔案看起來像這樣
spring.jpa.show-sql= true
spring.datasource.url= jdbc:postgresql://localhost:5432/Comapany
spring.datasource.username= postgres
spring.datasource.password= 0000
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true
spring.jpa.hibernate.ddl-auto= update
你能告訴我這里有什么問題嗎提前謝謝你。
uj5u.com熱心網友回復:
Spring 提供了一個特定于 JPA 的屬性,Hibernate 可以使用它來生成 DDL:spring.jpa.hibernate.ddl-auto
Hibernate 屬性包括:create、update、create-drop、validate和none。
- create:Hibernate 將首先洗掉現有表,然后創建新表。
- 更新:基于映射創建的物件模型與模式中的現有資料進行比較,然后 Hibernate 將使用新資訊更新模式。即使您的應用程式不再需要它們,它也永遠不會洗掉現有的表或列。
- create-drop:類似于create,但是在所有操作完成后,Hibernate 會洗掉資料庫。通常用于單元測驗。
- validate:Hibernate 只驗證表和列是否存在,否則會拋出例外。
- none:此值用于禁用 DDL 生成。
uj5u.com熱心網友回復:
嘗試這個:
@Entity
@Table("person")
//or what table name you used in your database for Person
public class Person{
}
uj5u.com熱心網友回復:
我認為您在 application.properties 檔案中缺少一些屬性值,請檢查以下檔案可能對您有所幫助
spring.datasource.name=localSource
spring.jpa.generate-ddl=true
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql= true
spring.datasource.url= jdbc:postgresql://localhost:5432/Comapany
spring.datasource.username= postgres
spring.datasource.password= 0000
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true
spring.jpa.hibernate.ddl-auto= update
我希望,它有幫助!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/514388.html
標籤:弹簧靴
