不能使用DefaultComponentSafeNamingStrategy
与Hibernate 5,因为它是由Hibernate老NamingStrategy
接口的实现4.
正如你可能知道,休眠5使用了两个新接口ImplicitNamingStrategy
和PhysicalNamingStrategy
。
您可以使用这种隐式命名策略:org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
。 您需要设置hibernate.implicit_naming_strategy
属性(而不是hibernate.ejb.naming_strategy
)。
对于这些实体
@Embeddable
public class AuthorInfo {
@Column
private String authorInfo;
@OneToOne
private Book bestBook;
}
@Entity
public class Book {
@Id
private Long pid;
@Embedded
private AuthorInfo firstAuthor;
@Embedded
private AuthorInfo secondAuthor;
}
它创建了一个架构
create table Book (
pid bigint not null,
firstAuthor_authorInfo varchar(255),
secondAuthor_authorInfo varchar(255),
firstAuthor_bestBook_pid bigint,
secondAuthor_bestBook_pid bigint,
primary key (pid)
)
单元测试,以检查一个模式:TwoEmbeddedStrategyTest.java
我使用的标注@column和使用该org.hibernate.boot。 model.naming.ImplicitNamingStrategyComponentPathImpl并且不起作用,但是在删除它的注释之后。 – Elhamo
@Elhamo我用Hibernate SessionFactory检查了这个,而不是用PersistentContext。这可能是一个原因,但我不确定。你可能会错过一些东西。 –