diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java index 6a6e63b3adde..a6486608c77b 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java @@ -326,15 +326,13 @@ public static Properties asProperties(Map map) { * @return will never return null, but might return an immutable collection. */ public static Set toSmallSet(Set set) { - switch ( set.size() ) { - case 0: - return emptySet(); - case 1: - return singleton( set.iterator().next() ); - default: - //TODO assert tests pass even if this is set to return an unmodifiable Set - return set; - } + return switch ( set.size() ) { + case 0 -> emptySet(); + case 1 -> singleton( set.iterator().next() ); + //TODO assert tests pass even if this is set to return an unmodifiable Set + default -> set; + + }; } /** @@ -345,16 +343,16 @@ public static Set toSmallSet(Set set) { * The goal is to save memory. */ public static Map toSmallMap(final Map map) { - switch ( map.size() ) { - case 0: - return emptyMap(); - case 1: - Map.Entry entry = map.entrySet().iterator().next(); - return singletonMap( entry.getKey(), entry.getValue() ); - default: - //TODO assert tests pass even if this is set to return an unmodifiable Map - return map; - } + return switch ( map.size() ) { + case 0 -> emptyMap(); + case 1 -> { + var entry = map.entrySet().iterator().next(); + yield singletonMap( entry.getKey(), entry.getValue() ); + } + //TODO assert tests pass even if this is set to return an unmodifiable Map + default -> map; + + }; } /** @@ -365,15 +363,14 @@ public static Map toSmallMap(final Map map) { * The goal is to save memory. */ public static List toSmallList(ArrayList arrayList) { - switch ( arrayList.size() ) { - case 0: - return emptyList(); - case 1: - return singletonList( arrayList.get( 0 ) ); - default: + return switch ( arrayList.size() ) { + case 0 -> emptyList(); + case 1 -> singletonList( arrayList.get( 0 ) ); + default -> { arrayList.trimToSize(); - return arrayList; - } + yield arrayList; + } + }; } public static List combine(List list1, List list2) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 4412a833d981..dcc15219b0b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1889,9 +1889,10 @@ public String selectFragment(String alias, String suffix) { for ( ; i < sqlSelections.size(); i++ ) { final SqlSelection sqlSelection = sqlSelections.get( i ); final ColumnReference columnReference = (ColumnReference) sqlSelection.getExpression(); - final String selectAlias = !columnReference.isColumnExpressionFormula() - ? columnAliases[columnIndex++] + suffix - : formulaAliases[formulaIndex++] + suffix; + final String selectAlias = + columnReference.isColumnExpressionFormula() + ? formulaAliases[formulaIndex++] + suffix + : columnAliases[columnIndex++] + suffix; sqlSelections.set( i, new SqlSelectionImpl( @@ -1916,50 +1917,48 @@ private ImmutableFetchList fetchProcessor(FetchParent fetchParent, LoaderSqlAstC final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer(); final int size = fetchableContainer.getNumberOfFetchables(); final ImmutableFetchList.Builder fetches = new ImmutableFetchList.Builder( fetchableContainer ); - for ( int i = 0; i < size; i++ ) { final Fetchable fetchable = fetchableContainer.getFetchable( i ); // Ignore plural attributes if ( !( fetchable instanceof PluralAttributeMapping ) ) { final FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming(); - if ( fetchable.asBasicValuedModelPart() != null ) { - // Ignore lazy basic columns - if ( fetchTiming == FetchTiming.DELAYED ) { - continue; - } - } - else if ( fetchable instanceof Association association ) { - // Ignore the fetchable if the FK is on the other side - if ( association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET ) { - continue; + if ( !skipFetchable( fetchable, fetchTiming ) ) { + if ( fetchTiming == null ) { + throw new AssertionFailure( "fetchTiming was null" ); } - // Ensure the FK comes from the root table - if ( !getRootTableName().equals( association.getForeignKeyDescriptor().getKeyTable() ) ) { - continue; + if ( fetchable.isSelectable() ) { + final Fetch fetch = fetchParent.generateFetchableFetch( + fetchable, + fetchParent.resolveNavigablePath( fetchable ), + fetchTiming, + false, + null, + creationState + ); + fetches.add( fetch ); } } - - if ( fetchTiming == null ) { - throw new AssertionFailure("fetchTiming was null"); - } - - if ( fetchable.isSelectable() ) { - final Fetch fetch = fetchParent.generateFetchableFetch( - fetchable, - fetchParent.resolveNavigablePath( fetchable ), - fetchTiming, - false, - null, - creationState - ); - fetches.add( fetch ); - } } } - return fetches.build(); } + private boolean skipFetchable(Fetchable fetchable, FetchTiming fetchTiming) { + if ( fetchable.asBasicValuedModelPart() != null ) { + // Ignore lazy basic columns + return fetchTiming == FetchTiming.DELAYED; + } + else if ( fetchable instanceof Association association ) { + // Ignore the fetchable if the FK is on the other side + return association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET + // Ensure the FK comes from the root table + || !getRootTableName().equals( association.getForeignKeyDescriptor().getKeyTable() ); + } + else { + return false; + } + } + @Override public String[] getIdentifierAliases(String suffix) { // NOTE: this assumes something about how propertySelectFragment is implemented by the subclass!