在假设这是一个重复之前,我知道这些答案(其中包括):
但是,自动创建一个表不起作用!
我使用了不同版本的Hibernate、Spring,甚至从JpaBaseConfiguration实现了类JpaConfig,并从通用应用特性添加了尊重属性
预期结果:
运行hbm2ddl模式更新
实际结果:
运行hbm2ddl模式导出
我看到了org.hibernate.cfj.Configuration Iterator<Table> getTableMappings(),但是这个方法返回emty列表而不是映射class->表。
任何帮助都将不胜感激。
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发布于 2017-01-14 18:47:40
只需在您的配置中添加以下内容:
spring:
jpa:
hibernate:
ddl-auto: none
properties:
hibernate.hbm2ddl.auto: create-drop对我来说很好,使用1.4.3。
发布于 2017-01-18 13:02:14
我也面临着同样的问题,但在我的例子中,只有一个实体不是自动创建在我的数据库上的,让我们一起来解决。
我的派对就像:
@Entity
@Table(name = "tablename")
public class ClassName {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
...试着把上面的注释放在上面,然后告诉我是否有效。
Tks。
https://stackoverflow.com/questions/41648846
复制相似问题