1212import org .hibernate .engine .internal .Nullability .NullabilityCheckType ;
1313import org .hibernate .engine .spi .CachedNaturalIdValueSource ;
1414import org .hibernate .engine .spi .CollectionKey ;
15- import org .hibernate .engine .spi .EntityEntry ;
16- import org .hibernate .engine .spi .EntityHolder ;
1715import org .hibernate .engine .spi .EntityKey ;
16+ import org .hibernate .engine .spi .NaturalIdResolutions ;
1817import org .hibernate .engine .spi .PersistenceContext ;
1918import org .hibernate .engine .spi .Status ;
2019import org .hibernate .event .spi .EventSource ;
21- import org .hibernate .metamodel .mapping .AttributeMapping ;
22- import org .hibernate .metamodel .mapping .AttributeMappingsList ;
23- import org .hibernate .metamodel .mapping .EmbeddableMappingType ;
24- import org .hibernate .metamodel .mapping .NaturalIdMapping ;
2520import org .hibernate .metamodel .mapping .PluralAttributeMapping ;
2621import org .hibernate .metamodel .mapping .internal .EmbeddedAttributeMapping ;
27- import org .hibernate .persister .collection .CollectionPersister ;
2822import org .hibernate .persister .entity .AbstractEntityPersister ;
2923import org .hibernate .persister .entity .EntityPersister ;
3024
@@ -134,12 +128,9 @@ protected final void nullifyTransientReferencesIfNotAlready() {
134128 public final void makeEntityManaged () {
135129 nullifyTransientReferencesIfNotAlready ();
136130 final Object version = getVersion ( getState (), getPersister () );
137- final PersistenceContext persistenceContextInternal = getSession ().getPersistenceContextInternal ();
138- final EntityHolder entityHolder = persistenceContextInternal .addEntityHolder (
139- getEntityKey (),
140- getInstance ()
141- );
142- final EntityEntry entityEntry = persistenceContextInternal .addEntry (
131+ final var persistenceContext = getSession ().getPersistenceContextInternal ();
132+ final var entityHolder = persistenceContext .addEntityHolder ( getEntityKey (), getInstance () );
133+ final var entityEntry = persistenceContext .addEntry (
143134 getInstance (),
144135 getPersister ().isMutable () ? Status .MANAGED : Status .READ_ONLY ,
145136 getState (),
@@ -153,13 +144,13 @@ public final void makeEntityManaged() {
153144 );
154145 entityHolder .setEntityEntry ( entityEntry );
155146 if ( isEarlyInsert () ) {
156- addCollectionsByKeyToPersistenceContext ( persistenceContextInternal , getState () );
147+ addCollectionsByKeyToPersistenceContext ( persistenceContext , getState () );
157148 }
158149 }
159150
160151 protected void addCollectionsByKeyToPersistenceContext (PersistenceContext persistenceContext , Object [] objects ) {
161152 for ( int i = 0 ; i < objects .length ; i ++ ) {
162- final AttributeMapping attributeMapping = getPersister ().getAttributeMapping ( i );
153+ final var attributeMapping = getPersister ().getAttributeMapping ( i );
163154 if ( attributeMapping .isEmbeddedAttributeMapping () ) {
164155 visitEmbeddedAttributeMapping (
165156 attributeMapping .asEmbeddedAttributeMapping (),
@@ -182,13 +173,12 @@ private void visitEmbeddedAttributeMapping(
182173 Object object ,
183174 PersistenceContext persistenceContext ) {
184175 if ( object != null ) {
185- final EmbeddableMappingType descriptor = attributeMapping .getEmbeddableTypeDescriptor ();
186- final EmbeddableMappingType .ConcreteEmbeddableType concreteEmbeddableType = descriptor .findSubtypeBySubclass (
187- object .getClass ().getName ()
188- );
189- final AttributeMappingsList attributeMappings = descriptor .getAttributeMappings ();
176+ final var descriptor = attributeMapping .getEmbeddableTypeDescriptor ();
177+ final var concreteEmbeddableType =
178+ descriptor .findSubtypeBySubclass ( object .getClass ().getName () );
179+ final var attributeMappings = descriptor .getAttributeMappings ();
190180 for ( int i = 0 ; i < attributeMappings .size (); i ++ ) {
191- final AttributeMapping attribute = attributeMappings .get ( i );
181+ final var attribute = attributeMappings .get ( i );
192182 if ( concreteEmbeddableType .declaresAttribute ( attribute ) ) {
193183 if ( attribute .isPluralAttributeMapping () ) {
194184 addCollectionKey (
@@ -214,15 +204,15 @@ private void addCollectionKey(
214204 Object object ,
215205 PersistenceContext persistenceContext ) {
216206 if ( object instanceof PersistentCollection ) {
217- final CollectionPersister collectionPersister = pluralAttributeMapping .getCollectionDescriptor ();
207+ final var collectionPersister = pluralAttributeMapping .getCollectionDescriptor ();
218208 final Object key = AbstractEntityPersister .getCollectionKey (
219209 collectionPersister ,
220210 getInstance (),
221211 persistenceContext .getEntry ( getInstance () ),
222212 getSession ()
223213 );
224214 if ( key != null ) {
225- final CollectionKey collectionKey = new CollectionKey ( collectionPersister , key );
215+ final var collectionKey = new CollectionKey ( collectionPersister , key );
226216 persistenceContext .addCollectionByKey ( collectionKey , (PersistentCollection <?>) object );
227217 }
228218 }
@@ -243,13 +233,17 @@ protected void markExecuted() {
243233
244234 protected abstract Object getRowId ();
245235
236+ private NaturalIdResolutions getNaturalIdResolutions () {
237+ return getSession ().getPersistenceContextInternal ().getNaturalIdResolutions ();
238+ }
239+
246240 @ Override
247241 public void afterDeserialize (EventSource session ) {
248242 super .afterDeserialize ( session );
249243 // IMPL NOTE: non-flushed changes code calls this method with session == null...
250244 // guard against NullPointerException
251245 if ( session != null ) {
252- final EntityEntry entityEntry = session .getPersistenceContextInternal ().getEntry ( getInstance () );
246+ final var entityEntry = session .getPersistenceContextInternal ().getEntry ( getInstance () );
253247 this .state = entityEntry .getLoadedState ();
254248 }
255249 }
@@ -259,9 +253,9 @@ public void afterDeserialize(EventSource session) {
259253 */
260254 protected void handleNaturalIdPreSaveNotifications () {
261255 // before save, we need to add a natural id cross-reference to the persistence-context
262- final NaturalIdMapping naturalIdMapping = getPersister ().getNaturalIdMapping ();
256+ final var naturalIdMapping = getPersister ().getNaturalIdMapping ();
263257 if ( naturalIdMapping != null ) {
264- getSession (). getPersistenceContextInternal (). getNaturalIdResolutions ().manageLocalResolution (
258+ getNaturalIdResolutions ().manageLocalResolution (
265259 getId (),
266260 naturalIdMapping .extractNaturalIdFromEntityState ( state ),
267261 getPersister (),
@@ -276,20 +270,21 @@ protected void handleNaturalIdPreSaveNotifications() {
276270 * @param generatedId The generated entity identifier
277271 */
278272 public void handleNaturalIdPostSaveNotifications (Object generatedId ) {
279- final NaturalIdMapping naturalIdMapping = getPersister ().getNaturalIdMapping ();
273+ final var naturalIdMapping = getPersister ().getNaturalIdMapping ();
280274 if ( naturalIdMapping != null ) {
281275 final Object naturalIdValues = naturalIdMapping .extractNaturalIdFromEntityState ( state );
276+ final var resolutions = getNaturalIdResolutions ();
282277 if ( isEarlyInsert () ) {
283278 // with early insert, we still need to add a local (transactional) natural id cross-reference
284- getSession (). getPersistenceContextInternal (). getNaturalIdResolutions () .manageLocalResolution (
279+ resolutions .manageLocalResolution (
285280 generatedId ,
286281 naturalIdValues ,
287282 getPersister (),
288283 CachedNaturalIdValueSource .INSERT
289284 );
290285 }
291286 // after save, we need to manage the shared cache entries
292- getSession (). getPersistenceContextInternal (). getNaturalIdResolutions () .manageSharedResolution (
287+ resolutions .manageSharedResolution (
293288 generatedId ,
294289 naturalIdValues ,
295290 null ,
0 commit comments