【发布时间】:2017-05-29 15:58:42
【问题描述】:
在您认为这是重复之前,我知道这些答案(以及其他):
- Hibernate not creating Table automatically in spring boot using postgresql
- Unable to get Spring boot to automatically create database schema
- Spring Boot + Hibernate + Postgres - not creating tables
不过,自动创建表格不起作用!
我使用了不同版本的Hibernate、Spring,甚至从JpaBaseConfiguration实现了类JpaConfig,并从common application properties添加了尊重属性
预期结果:
运行 hbm2ddl 架构更新
实际结果:
运行 hbm2ddl 模式导出
我看到了 org.hibernate.cfj.Configuration Iterator<Table> getTableMappings() ,但是这个方法返回的是 emty 列表而不是映射类->表
任何帮助将不胜感激。
Application.yml:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/task-manager
username: postgres
password: password
schema: public
jpa:
generate-ddl: true
hibernate:
naming-strategy: ru.ssau.common.naming_strategy.CustomNamingStrategy
ddl-auto: create-drop
logging:
level:
org:
hibernate:
SQL: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE
添加属性 driverClassName 不能解决它:
我的实体:
@Entity(name = "simple_user")
public class User extends PersistentObject {
@Column(unique = true, nullable = false)
private String nickname;
@OneToOne
@JoinColumn(name = "user_account_id")
private UserAccount userAccount;
public User() {
}
public User(String nickname) {
this.nickname = nickname;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public UserAccount getUserAccount() {
return userAccount;
}
public void setUserAccount(UserAccount userAccount) {
this.userAccount = userAccount;
}
}
Hibernate 从控制台的输出:
HHH000412: Hibernate Core {4.3.11.Final}
HHH000206: hibernate.properties not found
HHH000021: Bytecode provider name : javassist
HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
HHH000397: Using ASTQueryTranslatorFactory
HHH000227: Running hbm2ddl schema export
HHH000230: Schema export complete
【问题讨论】:
标签: java postgresql hibernate spring-data-jpa