66
77import java .lang .reflect .Method ;
88import java .util .LinkedHashMap ;
9+ import java .util .LinkedHashSet ;
910import java .util .Locale ;
1011import java .util .Map ;
1112import java .util .Set ;
1718import org .hibernate .bytecode .spi .ReflectionOptimizer ;
1819import org .hibernate .internal .CoreLogging ;
1920import org .hibernate .internal .CoreMessageLogger ;
20- import org .hibernate .mapping .Backref ;
2121import org .hibernate .mapping .Component ;
22- import org .hibernate .mapping .IndexBackref ;
23- import org .hibernate .mapping .KeyValue ;
2422import org .hibernate .mapping .PersistentClass ;
2523import org .hibernate .mapping .Property ;
2624import org .hibernate .mapping .Subclass ;
2927import org .hibernate .metamodel .spi .EntityRepresentationStrategy ;
3028import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
3129import org .hibernate .persister .entity .EntityPersister ;
32- import org .hibernate .property .access .internal .PropertyAccessStrategyBackRefImpl ;
33- import org .hibernate .property .access .internal .PropertyAccessStrategyIndexBackRefImpl ;
34- import org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies ;
3530import org .hibernate .property .access .spi .PropertyAccess ;
36- import org .hibernate .property .access .spi .PropertyAccessStrategy ;
3731import org .hibernate .proxy .HibernateProxy ;
3832import org .hibernate .proxy .ProxyFactory ;
3933import org .hibernate .tuple .entity .EntityMetamodel ;
4438
4539import static org .hibernate .engine .internal .ManagedTypeHelper .isPersistentAttributeInterceptableType ;
4640import static org .hibernate .internal .util .ReflectHelper .getMethod ;
47- import static org .hibernate .internal .util . StringHelper . isNotEmpty ;
41+ import static org .hibernate .metamodel . internal .PropertyAccessHelper . propertyAccessStrategy ;
4842import static org .hibernate .proxy .pojo .ProxyFactoryHelper .validateGetterSetterMethodProxyability ;
4943
5044/**
@@ -88,33 +82,19 @@ public EntityRepresentationStrategyPojoStandard(
8882 identifierPropertyName = null ;
8983 identifierPropertyAccess = null ;
9084
91- final KeyValue bootDescriptorIdentifier = bootDescriptor .getIdentifier ();
92-
93- if ( bootDescriptorIdentifier instanceof Component descriptorIdentifierComponent ) {
85+ if ( bootDescriptor .getIdentifier () instanceof Component descriptorIdentifierComponent ) {
9486 final Component identifierMapper = bootDescriptor .getIdentifierMapper ();
95- if ( identifierMapper != null ) {
96- mapsIdRepresentationStrategy = new EmbeddableRepresentationStrategyPojo (
97- identifierMapper ,
98- () -> ( ( CompositeTypeImplementor ) bootDescriptor .getIdentifierMapper ().getType () )
99- .getMappingModelPart ().getEmbeddableTypeDescriptor (),
100- // we currently do not support custom instantiators for identifiers
101- null ,
102- null ,
103- creationContext
104- );
105- }
106- else {
107- mapsIdRepresentationStrategy = new EmbeddableRepresentationStrategyPojo (
108- descriptorIdentifierComponent ,
109- // TODO: something wrong here: bootDescriptor.getIdentifierMapper() was null!
110- () -> ( ( CompositeTypeImplementor ) bootDescriptor .getIdentifierMapper ().getType () )
111- .getMappingModelPart ().getEmbeddableTypeDescriptor (),
112- // we currently do not support custom instantiators for identifiers
113- null ,
114- null ,
115- creationContext
116- );
117- }
87+ mapsIdRepresentationStrategy = new EmbeddableRepresentationStrategyPojo (
88+ identifierMapper == null ? descriptorIdentifierComponent : identifierMapper ,
89+ () -> {
90+ final var type = (CompositeTypeImplementor ) bootDescriptor .getIdentifierMapper ().getType ();
91+ return type .getMappingModelPart ().getEmbeddableTypeDescriptor ();
92+ },
93+ // we currently do not support custom instantiators for identifiers
94+ null ,
95+ null ,
96+ creationContext
97+ );
11898 }
11999 else {
120100 mapsIdRepresentationStrategy = null ;
@@ -146,36 +126,35 @@ public EntityRepresentationStrategyPojoStandard(
146126 this .instantiator = determineInstantiator ( bootDescriptor , runtimeDescriptor .getEntityMetamodel () );
147127 }
148128
149- @ SuppressWarnings ("removal" )
150129 private ProxyFactory resolveProxyFactory (
151130 PersistentClass bootDescriptor ,
152131 EntityPersister entityPersister ,
153- JavaType <?> proxyJtd ,
132+ JavaType <?> proxyJavaType ,
154133 BytecodeProvider bytecodeProvider ,
155134 RuntimeModelCreationContext creationContext ) {
156- final EntityMetamodel entityMetamodel = entityPersister .getEntityMetamodel ();
157- final boolean enhancedForLazyLoading =
158- entityPersister .getBytecodeEnhancementMetadata ()
159- .isEnhancedForLazyLoading ();
160-
161135 // todo : `@ConcreteProxy` handling
162- if ( enhancedForLazyLoading
136+ if ( entityPersister . getBytecodeEnhancementMetadata (). isEnhancedForLazyLoading ()
163137 && bootDescriptor .getRootClass () == bootDescriptor
164138 && !bootDescriptor .hasSubclasses () ) {
165- // the entity is bytecode enhanced for lazy loading and is not part of an inheritance hierarchy,
139+ // the entity is bytecode enhanced for lazy loading
140+ // and is not part of an inheritance hierarchy,
166141 // so no need for a ProxyFactory
167142 return null ;
168143 }
169-
170- if ( proxyJtd != null && entityMetamodel .isLazy () ) {
171- final ProxyFactory proxyFactory = createProxyFactory ( bootDescriptor , bytecodeProvider , creationContext );
172- if ( proxyFactory == null ) {
173- entityMetamodel .setLazy ( false );
144+ else {
145+ final EntityMetamodel entityMetamodel = entityPersister .getEntityMetamodel ();
146+ if ( proxyJavaType != null && entityMetamodel .isLazy () ) {
147+ final ProxyFactory proxyFactory =
148+ createProxyFactory ( bootDescriptor , bytecodeProvider , creationContext );
149+ if ( proxyFactory == null ) {
150+ entityMetamodel .setLazy ( false );
151+ }
152+ return proxyFactory ;
153+ }
154+ else {
155+ return null ;
174156 }
175- return proxyFactory ;
176157 }
177-
178- return null ;
179158 }
180159
181160 private Map <String , PropertyAccess > buildPropertyAccessMap (PersistentClass bootDescriptor ) {
@@ -209,7 +188,7 @@ private ProxyFactory createProxyFactory(
209188 // that the most general @Proxy declared interface at the top of a class
210189 // hierarchy will be used first when a HibernateProxy decides what it
211190 // should implement.
212- final Set <Class <?>> proxyInterfaces = new java . util . LinkedHashSet <>();
191+ final Set <Class <?>> proxyInterfaces = new LinkedHashSet <>();
213192
214193 final Class <?> mappedClass = mappedJtd .getJavaTypeClass ();
215194 final Class <?> proxyInterface = proxyJtd != null ? proxyJtd .getJavaTypeClass () : null ;
@@ -306,32 +285,8 @@ private ReflectionOptimizer resolveReflectionOptimizer(BytecodeProvider bytecode
306285 }
307286
308287 private PropertyAccess makePropertyAccess (Property bootAttributeDescriptor ) {
309- PropertyAccessStrategy strategy = bootAttributeDescriptor .getPropertyAccessStrategy ( mappedJtd .getJavaTypeClass () );
310-
311- if ( strategy == null ) {
312- final String propertyAccessorName = bootAttributeDescriptor .getPropertyAccessorName ();
313- if ( isNotEmpty ( propertyAccessorName ) ) {
314- // handle explicitly specified attribute accessor
315- strategy = strategySelector .resolveStrategy ( PropertyAccessStrategy .class , propertyAccessorName );
316- }
317- else {
318- if ( bootAttributeDescriptor instanceof Backref backref ) {
319- strategy = new PropertyAccessStrategyBackRefImpl ( backref .getCollectionRole (), backref
320- .getEntityName () );
321- }
322- else if ( bootAttributeDescriptor instanceof IndexBackref indexBackref ) {
323- strategy = new PropertyAccessStrategyIndexBackRefImpl (
324- indexBackref .getCollectionRole (),
325- indexBackref .getEntityName ()
326- );
327- }
328- else {
329- // for now...
330- strategy = BuiltInPropertyAccessStrategies .MIXED .getStrategy ();
331- }
332- }
333- }
334-
288+ final Class <?> mappedClass = mappedJtd .getJavaTypeClass ();
289+ final var strategy = propertyAccessStrategy ( bootAttributeDescriptor , mappedClass , strategySelector );
335290 if ( strategy == null ) {
336291 throw new HibernateException (
337292 String .format (
@@ -342,8 +297,7 @@ else if ( bootAttributeDescriptor instanceof IndexBackref indexBackref ) {
342297 )
343298 );
344299 }
345-
346- return strategy .buildPropertyAccess ( mappedJtd .getJavaTypeClass (), bootAttributeDescriptor .getName (), true );
300+ return strategy .buildPropertyAccess ( mappedClass , bootAttributeDescriptor .getName (), true );
347301 }
348302
349303 @ Override
@@ -386,16 +340,17 @@ public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) {
386340 if ( bootAttributeDescriptor .getName ().equals ( identifierPropertyName ) ) {
387341 return identifierPropertyAccess ;
388342 }
389-
390- final PropertyAccess propertyAccess = propertyAccessMap .get ( bootAttributeDescriptor .getName () );
391- if ( propertyAccess != null ) {
392- return propertyAccess ;
393- }
394-
395- if ( mapsIdRepresentationStrategy != null ) {
396- return mapsIdRepresentationStrategy .resolvePropertyAccess ( bootAttributeDescriptor );
343+ else {
344+ final PropertyAccess propertyAccess = propertyAccessMap .get ( bootAttributeDescriptor .getName () );
345+ if ( propertyAccess != null ) {
346+ return propertyAccess ;
347+ }
348+ else if ( mapsIdRepresentationStrategy != null ) {
349+ return mapsIdRepresentationStrategy .resolvePropertyAccess ( bootAttributeDescriptor );
350+ }
351+ else {
352+ return null ;
353+ }
397354 }
398-
399- return null ;
400355 }
401356}
0 commit comments