1010import org .hibernate .SessionException ;
1111import org .hibernate .boot .spi .SessionFactoryOptions ;
1212import org .hibernate .engine .spi .EntityKey ;
13+ import org .hibernate .engine .spi .SessionFactoryImplementor ;
1314import org .hibernate .engine .spi .SharedSessionContractImplementor ;
1415import org .hibernate .internal .CoreLogging ;
1516import org .hibernate .internal .CoreMessageLogger ;
1617import org .hibernate .internal .SessionFactoryRegistry ;
17- import org .hibernate .metamodel .spi .MappingMetamodelImplementor ;
1818import org .hibernate .persister .entity .EntityPersister ;
1919
2020/**
2525 * @author Gavin King
2626 */
2727public abstract class AbstractLazyInitializer implements LazyInitializer {
28+
2829 private static final CoreMessageLogger LOG = CoreLogging .messageLogger ( AbstractLazyInitializer .class );
2930
3031 private final String entityName ;
@@ -77,20 +78,22 @@ public final Object getIdentifier() {
7778 return id ;
7879 }
7980
80- private MappingMetamodelImplementor getMappingMetamodel () {
81- return session .getFactory (). getMappingMetamodel () ;
81+ private SessionFactoryImplementor getFactory () {
82+ return session .getFactory ();
8283 }
8384
84- private EntityPersister getEntityDescriptor () {
85- return getMappingMetamodel ().getEntityDescriptor ( entityName );
85+ public EntityPersister getEntityDescriptor () {
86+ return getFactory (). getMappingMetamodel ().getEntityDescriptor ( entityName );
8687 }
8788
8889 private SessionFactoryOptions getSessionFactoryOptions () {
89- return session . getFactory ().getSessionFactoryOptions ();
90+ return getFactory ().getSessionFactoryOptions ();
9091 }
9192
9293 private boolean isInitializeProxyWhenAccessingIdentifier () {
93- return session != null && getSessionFactoryOptions ().getJpaCompliance ().isJpaProxyComplianceEnabled ();
94+ return session != null
95+ && getSessionFactoryOptions ().getJpaCompliance ()
96+ .isJpaProxyComplianceEnabled ();
9497 }
9598
9699 @ Override
@@ -208,8 +211,10 @@ protected void permissiveInitialization() {
208211 session .getPersistenceContext ().setDefaultReadOnly ( true );
209212 session .setHibernateFlushMode ( FlushMode .MANUAL );
210213
211- final boolean isJTA = session .getTransactionCoordinator ().getTransactionCoordinatorBuilder ().isJta ();
212-
214+ final boolean isJTA =
215+ session .getTransactionCoordinator ()
216+ .getTransactionCoordinatorBuilder ()
217+ .isJta ();
213218 if ( !isJTA ) {
214219 // Explicitly handle the transactions only if we're not in
215220 // a JTA environment. A lazy loading temporary session can
@@ -262,8 +267,7 @@ else if ( session.isOpenOrWaitingForAutoClose() && session.isConnected() ) {
262267 */
263268 public final void initializeWithoutLoadIfPossible () {
264269 if ( !initialized && session != null && session .isOpenOrWaitingForAutoClose () ) {
265- final var entityDescriptor = getMappingMetamodel ().getEntityDescriptor ( getEntityName () );
266- final var key = session .generateEntityKey ( getInternalIdentifier (), entityDescriptor );
270+ final var key = session .generateEntityKey ( getInternalIdentifier (), getEntityDescriptor () );
267271 final Object entity = session .getPersistenceContextInternal ().getEntity ( key );
268272 if ( entity != null ) {
269273 setImplementation ( entity );
@@ -279,16 +283,15 @@ protected void prepareForPossibleLoadingOutsideTransaction() {
279283 if ( session != null ) {
280284 allowLoadOutsideTransaction =
281285 getSessionFactoryOptions ().isInitializeLazyStateOutsideTransactionsEnabled ();
282-
283286 if ( sessionFactoryUuid == null ) {
284287 // we're going to need the UUID even if the SessionFactory configuration doesn't
285288 // allow any operations on it, as we need it to match deserialized objects with
286289 // the originating SessionFactory: at very least it's useful to actually get
287290 // such configuration, so to know if such operation isn't allowed or configured otherwise.
288- sessionFactoryUuid = session . getFactory ().getUuid ();
291+ sessionFactoryUuid = getFactory ().getUuid ();
289292 }
290293 if ( sessionFactoryName == null ) {
291- sessionFactoryName = session . getFactory ().getName ();
294+ sessionFactoryName = getFactory ().getName ();
292295 }
293296 }
294297 }
@@ -312,10 +315,9 @@ protected final boolean isConnectedToSession() {
312315
313316 private Object getProxyOrNull () {
314317 final var entityKey = generateEntityKeyOrNull ( getInternalIdentifier (), session , getEntityName () );
315- if ( entityKey != null && session != null && session .isOpenOrWaitingForAutoClose () ) {
316- return session .getPersistenceContextInternal ().getProxy ( entityKey );
317- }
318- return null ;
318+ return entityKey != null && session != null && session .isOpenOrWaitingForAutoClose ()
319+ ? session .getPersistenceContextInternal ().getProxy ( entityKey )
320+ : null ;
319321 }
320322
321323 @ Override
@@ -344,7 +346,7 @@ public String getImplementationEntityName() {
344346 }
345347 if ( getEntityDescriptor ().hasSubclasses () ) {
346348 initialize ();
347- return session . getFactory ().bestGuessEntityName ( target );
349+ return getFactory ().bestGuessEntityName ( target );
348350 }
349351 return entityName ;
350352 }
0 commit comments