在你认为这是重复之前,我知道这些答案(以及其他):
但是,自动创建表格不起作用!
我使用了Hibernate
,Spring
的不同版本,甚至从JpaConfig
实现了类JpaBaseConfiguration
,并添加了来自common application properties
预期结果:
运行hbm2ddl架构更新
实际结果:
运行hbm2ddl架构导出
我看到org.hibernate.cfj.Configuration Iterator<Table> getTableMappings()
,但此方法返回emty列表而不是映射class-&gt; table
任何帮助都将不胜感激。
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
答案 0 :(得分:1)
只需添加以下配置:
spring:
jpa:
hibernate:
ddl-auto: none
properties:
hibernate.hbm2ddl.auto: create-drop
适合我,使用1.4.3.RELEASE。
答案 1 :(得分:0)
我面对同样的情况,但在我的情况下,我的数据库中没有自动创建各种实体中的一个,让我们一起尝试解决。
我的实体看起来像:
@Entity
@Table(name = "tablename")
public class ClassName {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
...
尝试如上所述的注释并告诉我是否有效。
韩国社交协会