如何使用Spring JPA和Maven在数据库中为实体创建表



如何在Postgres数据库中为下面的实体生成表?我使用maven构建。

实体:

@Entity
@Table(name = "EMPLOYEE")
public class Employee {
@Id @GeneratedValue
@Column(name = "id")
private int id;
}    

属性:

spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory         
spring.datasource.url=jdbc:postgresql://localhost:5433/con_db        
spring.datasource.username=postgres
spring.datasource.password=root        
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.default_schema=as2
spring.jpa.hibernate.naming.physical-strategy=com.ds.entity.strategy.EntityNamingStrategy
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true                
spring.jpa.show-sql=true        
spring.h2.console.enabled=true          
logging.level.org.hibernate.SQL=DEBUG  
logging.level.org.hibernate.type=TRACE

尝试使用hibernate default_schemapublic,而不是像这样使用as2spring.jpa.properties.hibernate.default_schema=public然后运行您的项目。

您必须运行spring-boot应用程序才能在postgres数据库中构建数据库结构,这与maven无关。感谢@Spartan在这里的帮助。

最新更新