@@ -32,28 +32,26 @@ public interface InheritanceChecker {
3232 * Should the given property be included in the owner's base fetch group?
3333 */
3434 public static boolean includeInBaseFetchGroup (
35- Property bootMapping ,
35+ Property property ,
3636 boolean isEnhanced ,
3737 InheritanceChecker inheritanceChecker ,
3838 boolean collectionsInDefaultFetchGroupEnabled ) {
39- final var value = bootMapping .getValue ();
40-
41- if ( ! isEnhanced ) {
42- if ( value instanceof ToOne toOne ) {
43- if ( toOne .isUnwrapProxy () ) {
44- BYTECODE_INTERCEPTOR_LOGGER .toOneLazyNoProxyButNotEnhanced (
45- bootMapping .getPersistentClass ().getEntityName (),
46- bootMapping .getName ()
47- );
48- }
39+ final var value = property .getValue ();
40+
41+ if ( !isEnhanced ) {
42+ if ( value instanceof ToOne toOne && toOne .isUnwrapProxy () ) {
43+ BYTECODE_INTERCEPTOR_LOGGER .toOneLazyNoProxyButNotEnhanced (
44+ property .getPersistentClass ().getEntityName (),
45+ property .getName ()
46+ );
4947 }
5048 return true ;
5149 }
5250
5351 // if we get here, we know the property owner is enhanced for laziness
5452 //
55- // NOTE : we make the (potentially untrue) assumption here that
56- // if the owner is enhanced, then all classes are enhanced. .
53+ // NOTE: we make the (potentially untrue) assumption here that
54+ // if the owner is enhanced, then all classes are enhanced.
5755
5856 if ( value instanceof ToOne toOne ) {
5957
@@ -64,17 +62,17 @@ public static boolean includeInBaseFetchGroup(
6462
6563 // it is lazy. see if we should select the FK
6664
67- if ( bootMapping .getLazyGroup () != null ) {
65+ if ( property .getLazyGroup () != null ) {
6866 // a non-base fetch group was explicitly specified
6967 //
7068 // really this should indicate to not select it as part of the base group.
7169 // however, at the time being that leads to inefficient SQL - so for now
7270 // we simply log a message that we are ignoring the `@LazyGroup` for to-ones
7371
7472 BYTECODE_INTERCEPTOR_LOGGER .lazyGroupIgnoredForToOne (
75- bootMapping .getLazyGroup (),
76- bootMapping .getPersistentClass ().getEntityName (),
77- bootMapping .getName ()
73+ property .getLazyGroup (),
74+ property .getPersistentClass ().getEntityName (),
75+ property .getName ()
7876 );
7977
8078 // at a later time - for example 6.0 when we can implement the join solution
@@ -84,29 +82,30 @@ public static boolean includeInBaseFetchGroup(
8482 // for now, fall through
8583 }
8684
87- if ( ! toOne .isReferenceToPrimaryKey () ) {
85+ if ( !toOne .isReferenceToPrimaryKey () ) {
8886 // we do not have a reference to the associated primary-key
8987 return false ;
9088 }
9189
9290 if ( toOne .getColumnSpan () == 0 ) {
93- // generally this would indicate a "shared PK" on -to-one and there
91+ // generally this would indicate a "shared PK" one -to-one and there
9492 // is no column for the association on the owner table - do not add
9593 // the association to the base group (which would force an immediate
9694 // select from the association table effectively making this
9795 // association non-lazy)
9896 return false ;
9997 }
10098
101- final boolean unwrapExplicitlyRequested = toOne .isUnwrapProxy () && !toOne .isUnwrapProxyImplicit ();
99+ final boolean unwrapExplicitlyRequested =
100+ toOne .isUnwrapProxy () && !toOne .isUnwrapProxyImplicit ();
102101
103102 if ( inheritanceChecker .hasSubclasses ( toOne .getReferencedEntityName () ) ) {
104103 // the associated type has subclasses - we cannot use the enhanced proxy and will generate a HibernateProxy
105104 if ( unwrapExplicitlyRequested ) {
106105 // NO_PROXY was explicitly requested
107106 BYTECODE_INTERCEPTOR_LOGGER .lazyNoProxyButAssociatedHasSubclasses (
108- bootMapping .getPersistentClass ().getEntityName (),
109- bootMapping .getName (),
107+ property .getPersistentClass ().getEntityName (),
108+ property .getName (),
110109 toOne .getReferencedEntityName ()
111110 );
112111 }
@@ -117,8 +116,8 @@ public static boolean includeInBaseFetchGroup(
117116 if ( toOne instanceof ManyToOne manyToOne && manyToOne .isIgnoreNotFound () ) {
118117 if ( unwrapExplicitlyRequested ) {
119118 BYTECODE_INTERCEPTOR_LOGGER .notFoundIgnoreWithNoProxySkippingFkSelection (
120- bootMapping .getPersistentClass ().getEntityName (),
121- bootMapping .getName ()
119+ property .getPersistentClass ().getEntityName (),
120+ property .getName ()
122121 );
123122 return false ;
124123 }
@@ -135,15 +134,15 @@ public static boolean includeInBaseFetchGroup(
135134 }
136135
137136 return collectionsInDefaultFetchGroupEnabled && ( value instanceof Collection )
138- || ! bootMapping .isLazy ();
137+ || ! property .isLazy ();
139138 }
140139
141140 public static <T > T performWork (
142141 BytecodeLazyAttributeInterceptor interceptor ,
143142 BiFunction <SharedSessionContractImplementor , Boolean , T > work ,
144143 String entityName ,
145144 String attributeName ) {
146- SharedSessionContractImplementor session = interceptor .getLinkedSession ();
145+ var session = interceptor .getLinkedSession ();
147146
148147 final boolean isTempSession ;
149148 final boolean isJta ;
@@ -236,23 +235,20 @@ enum Cause {
236235 NO_SF_UUID
237236 }
238237
239- private static LazyInitializationException createLazyInitializationException (final Cause cause , final String entityName , final String attributeName ) {
240- final String reason = switch ( cause ) {
241- case NO_SESSION -> "no session and settings disallow loading outside the Session" ;
242- case CLOSED_SESSION -> "session is closed and settings disallow loading outside the Session" ;
243- case DISCONNECTED_SESSION -> "session is disconnected and settings disallow loading outside the Session" ;
244- case NO_SF_UUID -> "could not determine SessionFactory UUId to create temporary Session for loading" ;
245- };
246-
247- final String message = String .format (
238+ private static LazyInitializationException createLazyInitializationException (
239+ Cause cause , String entityName , String attributeName ) {
240+ return new LazyInitializationException ( String .format (
248241 Locale .ROOT ,
249242 "Unable to perform requested lazy initialization [%s.%s] - %s" ,
250243 entityName ,
251244 attributeName ,
252- reason
253- );
254-
255- return new LazyInitializationException ( message );
245+ switch ( cause ) {
246+ case NO_SESSION -> "no session and settings disallow loading outside the Session" ;
247+ case CLOSED_SESSION -> "session is closed and settings disallow loading outside the Session" ;
248+ case DISCONNECTED_SESSION -> "session is disconnected and settings disallow loading outside the Session" ;
249+ case NO_SF_UUID -> "could not determine SessionFactory UUId to create temporary Session for loading" ;
250+ }
251+ ) );
256252 }
257253
258254 private static SharedSessionContractImplementor openTemporarySessionForLoading (
0 commit comments