Hibernate实现了一些标准的命名策略:
default
for org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl - an alias for jpa
jpa
for org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl - the JPA 2.0 compliant naming strategy
legacy-hbm
for org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl - compliant with the original Hibernate NamingStrategy
legacy-jpa
for org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl - compliant with the legacy NamingStrategy developed for JPA 1.0, which was unfortunately unclear in many respects regarding implicit naming rules.
component-path
for org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl - mostly follows ImplicitNamingStrategyJpaCompliantImpl rules, except that it uses the full composite paths, as opposed to just the ending property part
Run Code Online (Sandbox Code Playgroud)
但我找不到每个策略的任何例子.你知道我在哪里找到这样的例子吗?
Ana*_*mov 11
这是一个示例,它显示了这四种命名策略(使用Hibernate 5.2.11.RELEASE)之间的差异.
@Entity
@Table(name = "mainTable")
public class MainEntity {
@Id
private Long id;
@ElementCollection
Set<EmbeddableElement> mainElements;
@OneToMany(targetEntity = DependentEntity.class)
Set<DependentEntity> dependentEntities;
@OneToOne(targetEntity = OwnedEntity.class)
OwnedEntity ownedEntity;
}
@Entity
@Table(name = "dependentTable")
public class DependentEntity {
@Id
private Long id;
@ManyToOne
MainEntity mainEntity;
@ElementCollection
@CollectionTable(name = "dependentElements")
Set<EmbeddableElement> dependentElements;
}
@Entity(name = "`owned_table`")
public class OwnedEntity {
@Id
private Long id;
@ElementCollection
@CollectionTable
Set<EmbeddableElement> ownedElements;
}
@Embeddable
public class EmbeddableElement {
@Column(name = "`quotedField`")
String quotedField;
@Column
String regularField;
}
Run Code Online (Sandbox Code Playgroud)
默认命名策略.ImplicitNamingStrategy合同的实现,通常更喜欢符合JPA标准.
create table main_table
(id bigint not null, "owned_entity_id" bigint, primary key (id))
create table main_entity_main_elements
(main_entity_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
create table main_table_dependent_table
(main_entity_id bigint not null, dependent_entities_id bigint not null, primary key (main_entity_id, dependent_entities_id))
create table dependent_table
(id bigint not null, main_entity_id bigint, primary key (id))
create table dependent_elements
(dependent_entity_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
create table "owned_table"
(id bigint not null, primary key (id))
create table "`owned_table`_owned_elements"
("`owned_table`_id" bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
Run Code Online (Sandbox Code Playgroud)
实现原始的遗留命名行为.
与默认策略的主要区别是:
create table main_table
(id bigint not null, owned_entity bigint, primary key (id))
create table main_entity_main_elements
(main_entity_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
create table main_table_dependent_entities
(main_entity_id bigint not null, dependent_entities bigint not null, primary key (main_entity_id, dependent_entities))
create table dependent_table
(id bigint not null, main_entity bigint, primary key (id))
create table dependent_elements
(dependent_entity_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
create table owned_entity
(id bigint not null, primary key (id))
create table owned_entity_owned_elements
(owned_entity_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
Run Code Online (Sandbox Code Playgroud)
ImplicitNamingStrategy合同的实现,它符合Hibernate最初为JPA 1.0实现的命名规则,在许多事情得到澄清之前.
与默认策略的主要区别是:
create table main_table
(id bigint not null, "owned_entity_id" bigint, primary key (id))
create table main_table_main_elements
(main_table_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
create table main_table_dependent_table
(main_table_id bigint not null, dependent_entities_id bigint not null, primary key (main_table_id, dependent_entities_id))
create table dependent_table
(id bigint not null, main_entity_id bigint, primary key (id))
create table dependent_elements
(dependent_table_id bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
create table "owned_table"
(id bigint not null, primary key (id))
create table "owned_table_owned_elements"
("owned_table_id" bigint not null, "quoted_field" varchar(255), regular_field varchar(255))
Run Code Online (Sandbox Code Playgroud)
ImplicitNamingStrategy实现,它使用从AttributePath中提取的完整复合路径,而不仅仅是终端属性部分.
与默认策略的主要区别是:
create table main_table
(id bigint not null, "owned_entity_id" bigint, primary key (id))
create table main_entity_main_elements
(main_entity_id bigint not null, "quoted_field" varchar(255), main_elements_regular_field varchar(255))
create table main_table_dependent_table
(main_entity_id bigint not null, dependent_entities_id bigint not null, primary key (main_entity_id, dependent_entities_id))
create table dependent_table
(id bigint not null, main_entity_id bigint, primary key (id))
create table dependent_elements
(dependent_entity_id bigint not null, "quoted_field" varchar(255), dependent_elements_regular_field varchar(255))
create table "owned_table"
(id bigint not null, primary key (id))
create table "`owned_table`_owned_elements"
("`owned_table`_id" bigint not null, "quoted_field" varchar(255), owned_elements_regular_field varchar(255))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3998 次 |
| 最近记录: |