|
12 | 12 | import org.hibernate.annotations.EmbeddedTable; |
13 | 13 | import org.hibernate.boot.model.naming.Identifier; |
14 | 14 | import org.hibernate.boot.models.AnnotationPlacementException; |
15 | | -import org.hibernate.boot.spi.InFlightMetadataCollector; |
16 | 15 | import org.hibernate.boot.spi.MetadataBuildingContext; |
17 | 16 | import org.hibernate.boot.spi.PropertyData; |
18 | 17 | import org.hibernate.mapping.AggregateColumn; |
@@ -118,47 +117,48 @@ public static void applyExplicitTableName( |
118 | 117 | PropertyHolder container, |
119 | 118 | MetadataBuildingContext buildingContext) { |
120 | 119 | Table tableToUse = container.getTable(); |
121 | | -boolean wasExplicit = false; |
122 | | -if ( container instanceof ComponentPropertyHolder componentPropertyHolder ) { |
123 | | -wasExplicit = componentPropertyHolder.getComponent().wasTableExplicitlyDefined(); |
124 | | -} |
| 120 | +boolean wasExplicit = |
| 121 | +container instanceof ComponentPropertyHolder componentPropertyHolder |
| 122 | +&& componentPropertyHolder.getComponent().wasTableExplicitlyDefined(); |
125 | 123 |
|
126 | | -if ( propertyData.getAttributeMember() != null ) { |
127 | | -final EmbeddedTable embeddedTableAnn = propertyData.getAttributeMember() |
128 | | -.getDirectAnnotationUsage( EmbeddedTable.class ); |
| 124 | +final var attributeMember = propertyData.getAttributeMember(); |
| 125 | +if ( attributeMember != null ) { |
| 126 | +final var embeddedTableAnn = attributeMember.getDirectAnnotationUsage( EmbeddedTable.class ); |
129 | 127 | // we only allow this when done for an embedded on an entity or mapped-superclass |
130 | 128 | if ( container instanceof ClassPropertyHolder ) { |
131 | 129 | if ( embeddedTableAnn != null ) { |
132 | | -final Identifier tableNameIdentifier = buildingContext.getObjectNameNormalizer().normalizeIdentifierQuoting( embeddedTableAnn.value() ); |
133 | | -final InFlightMetadataCollector.EntityTableXref entityTableXref = buildingContext |
134 | | -.getMetadataCollector() |
135 | | -.getEntityTableXref( container.getEntityName() ); |
136 | | -tableToUse = entityTableXref.resolveTable( tableNameIdentifier ); |
| 130 | +tableToUse = resolveEmbeddedTable( container, buildingContext, embeddedTableAnn ); |
137 | 131 | wasExplicit = true; |
138 | 132 | } |
139 | 133 | } |
140 | | -else { |
141 | | -if ( embeddedTableAnn != null ) { |
142 | | -// not allowed |
143 | | -throw new AnnotationPlacementException( "@EmbeddedTable only supported for use on entity or mapped-superclass" ); |
144 | | -} |
| 134 | +else if ( embeddedTableAnn != null ) { |
| 135 | +// not allowed |
| 136 | +throw new AnnotationPlacementException( |
| 137 | +"@EmbeddedTable only supported for use on entity or mapped-superclass" ); |
145 | 138 | } |
146 | 139 | } |
147 | | -if ( propertyData.getAttributeMember() != null && container instanceof ClassPropertyHolder ) { |
148 | | -final EmbeddedTable embeddedTableAnn = propertyData.getAttributeMember().getDirectAnnotationUsage( EmbeddedTable.class ); |
| 140 | +if ( attributeMember != null && container instanceof ClassPropertyHolder ) { |
| 141 | +final var embeddedTableAnn = attributeMember.getDirectAnnotationUsage( EmbeddedTable.class ); |
149 | 142 | if ( embeddedTableAnn != null ) { |
150 | | -final Identifier tableNameIdentifier = buildingContext.getObjectNameNormalizer().normalizeIdentifierQuoting( embeddedTableAnn.value() ); |
151 | | -final InFlightMetadataCollector.EntityTableXref entityTableXref = buildingContext |
152 | | -.getMetadataCollector() |
153 | | -.getEntityTableXref( container.getEntityName() ); |
154 | | -tableToUse = entityTableXref.resolveTable( tableNameIdentifier ); |
| 143 | +tableToUse = resolveEmbeddedTable( container, buildingContext, embeddedTableAnn ); |
155 | 144 | wasExplicit = true; |
156 | 145 | } |
157 | 146 | } |
158 | 147 |
|
159 | 148 | component.setTable( tableToUse, wasExplicit ); |
160 | 149 | } |
161 | 150 |
|
| 151 | +private static Table resolveEmbeddedTable( |
| 152 | +PropertyHolder container, MetadataBuildingContext buildingContext, EmbeddedTable embeddedTableAnn) { |
| 153 | +final Identifier tableNameIdentifier = |
| 154 | +buildingContext.getObjectNameNormalizer() |
| 155 | +.normalizeIdentifierQuoting( embeddedTableAnn.value() ); |
| 156 | +final var entityTableXref = |
| 157 | +buildingContext.getMetadataCollector() |
| 158 | +.getEntityTableXref( container.getEntityName() ); |
| 159 | +return entityTableXref.resolveTable( tableNameIdentifier ); |
| 160 | +} |
| 161 | + |
162 | 162 | /** |
163 | 163 | * Access to the underlying component |
164 | 164 | */ |
@@ -235,21 +235,19 @@ protected String normalizeCompositePathForLogging(String attributeName) { |
235 | 235 | public void startingProperty(MemberDetails propertyMemberDetails) { |
236 | 236 | if ( propertyMemberDetails != null ) { |
237 | 237 | // again: the property coming in here *should* be the property on the embeddable (Address#city in the example), |
238 | | -// so we just ignore it if there is already an existing conversion info for that path since they would have |
| 238 | +// so we just ignore it if there is already an existing ConversionInfo for that path since they would have |
239 | 239 | // precedence |
240 | 240 |
|
241 | 241 | // technically we should only do this for properties of "basic type" |
242 | 242 |
|
243 | 243 | final String attributeName = propertyMemberDetails.resolveAttributeName(); |
244 | 244 | final String path = embeddedAttributeName + '.' + attributeName; |
245 | | -if ( attributeConversionInfoMap.containsKey( path ) ) { |
246 | | -return; |
| 245 | +if ( !attributeConversionInfoMap.containsKey( path ) ) { |
| 246 | +propertyMemberDetails.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { |
| 247 | +final var info = new AttributeConversionInfo( usage, propertyMemberDetails ); |
| 248 | +attributeConversionInfoMap.put( attributeName, info ); |
| 249 | +} ); |
247 | 250 | } |
248 | | - |
249 | | -propertyMemberDetails.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { |
250 | | -final AttributeConversionInfo info = new AttributeConversionInfo( usage, propertyMemberDetails ); |
251 | | -attributeConversionInfoMap.put( attributeName, info ); |
252 | | -} ); |
253 | 251 | } |
254 | 252 | } |
255 | 253 |
|
@@ -403,7 +401,7 @@ public void setParentProperty(String parentProperty) { |
403 | 401 | @Override |
404 | 402 | public Column[] getOverriddenColumn(String propertyName) { |
405 | 403 | //FIXME this is yukky |
406 | | -Column[] result = super.getOverriddenColumn( propertyName ); |
| 404 | +var result = super.getOverriddenColumn( propertyName ); |
407 | 405 | if ( result == null ) { |
408 | 406 | final String userPropertyName = extractUserPropertyName( "id", propertyName ); |
409 | 407 | if ( userPropertyName != null ) { |
@@ -434,6 +432,7 @@ private String extractUserPropertyName(String redundantString, String propertyNa |
434 | 432 |
|
435 | 433 | @Override |
436 | 434 | public String toString() { |
437 | | -return getClass().getSimpleName() + "(" + parent.normalizeCompositePathForLogging( embeddedAttributeName ) + ")"; |
| 435 | +return getClass().getSimpleName() |
| 436 | ++ "(" + parent.normalizeCompositePathForLogging( embeddedAttributeName ) + ")"; |
438 | 437 | } |
439 | 438 | } |
0 commit comments