Skip to content

Commit fa964ed

Browse files
committed
javadoc / code cleanup in ImplicitNamingStrategyJpaCompliantImpl
1 parent 11671ba commit fa964ed

File tree

1 file changed

+53
-62
lines changed

1 file changed

+53
-62
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/naming/ImplicitNamingStrategyJpaCompliantImpl.java

Lines changed: 53 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* preferring to conform to JPA standards.
2020
* <p>
2121
* For the legacy JPA-based naming standards initially implemented by Hibernate,
22-
* see/use {@link ImplicitNamingStrategyLegacyJpaImpl}
22+
* see/use {@link ImplicitNamingStrategyLegacyJpaImpl}.
2323
*
2424
* @author Steve Ebersole
2525
*/
@@ -31,55 +31,50 @@ public ImplicitNamingStrategyJpaCompliantImpl() {
3131

3232
@Override
3333
public Identifier determinePrimaryTableName(ImplicitEntityNameSource source) {
34-
if ( source == null ) {
35-
// should never happen, but to be defensive...
36-
throw new HibernateException( "Entity naming information was not provided." );
37-
}
38-
34+
assert source != null;
3935
final String tableName = transformEntityName( source.getEntityNaming() );
40-
4136
if ( tableName == null ) {
42-
// todo : add info to error message - but how to know what to write since we failed to interpret the naming source
43-
throw new HibernateException( "Could not determine primary table name for entity" );
37+
throw new HibernateException( "Could not determine primary table name for entity: "
38+
+ source.getEntityNaming().getClassName() );
4439
}
45-
4640
return toIdentifier( tableName, source.getBuildingContext() );
4741
}
4842

4943
protected String transformEntityName(EntityNaming entityNaming) {
50-
// prefer the JPA entity name, if specified...
51-
if ( isNotEmpty( entityNaming.getJpaEntityName() ) ) {
52-
return entityNaming.getJpaEntityName();
53-
}
54-
else {
55-
// otherwise, use the Hibernate entity name
56-
return unqualify( entityNaming.getEntityName() );
57-
}
44+
return isNotEmpty( entityNaming.getJpaEntityName() )
45+
// prefer the JPA entity name, if specified
46+
? entityNaming.getJpaEntityName()
47+
// otherwise, use the unqualified Hibernate entity name
48+
: unqualify( entityNaming.getEntityName() );
5849
}
5950

6051

52+
/**
53+
* JPA states we should use the following as default:
54+
* <blockquote>The concatenated names of the two associated primary entity
55+
* tables (owning side first), separated by an underscore.</blockquote>
56+
* That is:
57+
* <pre>{OWNING SIDE PRIMARY TABLE NAME}_{NON-OWNING SIDE PRIMARY TABLE NAME}</pre>
58+
*/
6159
@Override
6260
public Identifier determineJoinTableName(ImplicitJoinTableNameSource source) {
63-
// JPA states we should use the following as default:
64-
// "The concatenated names of the two associated primary entity tables (owning side
65-
// first), separated by an underscore."
66-
// aka:
67-
// {OWNING SIDE PRIMARY TABLE NAME}_{NON-OWNING SIDE PRIMARY TABLE NAME}
6861
final String name = source.getOwningPhysicalTableName()
6962
+ '_'
7063
+ source.getNonOwningPhysicalTableName();
7164
return toIdentifier( name, source.getBuildingContext() );
7265
}
7366

74-
67+
/**
68+
* JPA states we should use the following as default:
69+
* <blockquote>The concatenation of the name of the containing entity and the
70+
* name of the collection attribute, separated by an underscore.</blockquote>
71+
* That is, if owning entity has a JPA entity name:
72+
* <pre>{OWNER JPA ENTITY NAME}_{COLLECTION ATTRIBUTE NAME}</pre>
73+
* otherwise:
74+
* <pre>{OWNER ENTITY NAME}_{COLLECTION ATTRIBUTE NAME}</pre>
75+
*/
7576
@Override
7677
public Identifier determineCollectionTableName(ImplicitCollectionTableNameSource source) {
77-
// JPA states we should use the following as default:
78-
// "The concatenation of the name of the containing entity and the name of the
79-
// collection attribute, separated by an underscore.
80-
// aka:
81-
// if owning entity has a JPA entity name: {OWNER JPA ENTITY NAME}_{COLLECTION ATTRIBUTE NAME}
82-
// otherwise: {OWNER ENTITY NAME}_{COLLECTION ATTRIBUTE NAME}
8378
final String name = transformEntityName( source.getOwningEntityNaming() )
8479
+ '_'
8580
+ transformAttributePath( source.getOwningAttributePath() );
@@ -111,51 +106,47 @@ public Identifier determineTenantIdColumnName(ImplicitTenantIdColumnNameSource s
111106
);
112107
}
113108

109+
/**
110+
* JPA states we should use the following as default:
111+
* <blockquote>The property or field name</blockquote>
112+
* That is, the unqualified attribute path.
113+
*/
114114
@Override
115115
public Identifier determineBasicColumnName(ImplicitBasicColumnNameSource source) {
116-
// JPA states we should use the following as default:
117-
// "The property or field name"
118-
// aka:
119-
// The unqualified attribute path.
120116
return toIdentifier( transformAttributePath( source.getAttributePath() ), source.getBuildingContext() );
121117
}
122118

119+
/**
120+
* JPA states we should use the following as default:
121+
* <ul>
122+
* <li>If there is a "referencing relationship property":
123+
* <blockquote>The concatenation of the following: the name of the referencing
124+
* relationship property or field of the referencing entity or embeddable class;
125+
* {@code _}; the name of the referenced primary key column.</blockquote>
126+
* <li>If there is no such "referencing relationship property",
127+
* or if the association is an element collection:
128+
* <blockquote>The concatenation of the following: the name of the entity;
129+
* {@code _}; the name of the referenced primary key column</blockquote>
130+
* </ul>
131+
*/
123132
@Override
124133
public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) {
125-
// JPA states we should use the following as default:
126-
//
127-
// (1) if there is a "referencing relationship property":
128-
// "The concatenation of the following: the name of the referencing relationship
129-
// property or field of the referencing entity or embeddable class; "_"; the
130-
// name of the referenced primary key column."
131-
//
132-
// (2) if there is no such "referencing relationship property", or if the association is
133-
// an element collection:
134-
// "The concatenation of the following: the name of the entity; "_"; the name of the
135-
// referenced primary key column"
136-
137-
// todo : we need to better account for "referencing relationship property"
138-
134+
// TODO: we need to better account for "referencing relationship property"
135+
final String referencingPropertyOrEntity =
136+
source.getNature() == ELEMENT_COLLECTION || source.getAttributePath() == null
137+
? transformEntityName( source.getEntityNaming() )
138+
: transformAttributePath( source.getAttributePath() );
139139
final String referencedColumnName = source.getReferencedColumnName().getText();
140-
141-
final String name;
142-
if ( source.getNature() == ELEMENT_COLLECTION
143-
|| source.getAttributePath() == null ) {
144-
name = transformEntityName( source.getEntityNaming() )
145-
+ '_' + referencedColumnName;
146-
}
147-
else {
148-
name = transformAttributePath( source.getAttributePath() )
149-
+ '_' + referencedColumnName;
150-
}
151-
140+
final String name = referencingPropertyOrEntity + '_' + referencedColumnName;
152141
return toIdentifier( name, source.getBuildingContext() );
153142
}
154143

144+
/**
145+
* JPA states we should use the following as default:
146+
* <blockquote>the same name as the primary key column [of the referenced table]</blockquote>
147+
*/
155148
@Override
156149
public Identifier determinePrimaryKeyJoinColumnName(ImplicitPrimaryKeyJoinColumnNameSource source) {
157-
// JPA states we should use the following as default:
158-
// "the same name as the primary key column [of the referenced table]"
159150
return source.getReferencedPrimaryKeyColumnName();
160151
}
161152

0 commit comments

Comments
 (0)