diff --git a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java index 6e9aaa9721..bdb908ac9d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java @@ -20,12 +20,13 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.jpa.spi.JpaCompliance; import org.hibernate.loader.BatchFetchStyle; import org.hibernate.proxy.EntityNotFoundDelegate; -import org.hibernate.query.NullPrecedence; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.type.format.FormatMapper; +import jakarta.persistence.criteria.Nulls; + /** * The contract for building a {@link SessionFactory} given a specified set of options. * @@ -335,7 +336,7 @@ public interface SessionFactoryBuilder { * * @see org.hibernate.cfg.AvailableSettings#DEFAULT_NULL_ORDERING */ - SessionFactoryBuilder applyDefaultNullPrecedence(NullPrecedence nullPrecedence); + SessionFactoryBuilder applyDefaultNullPrecedence(Nulls nullPrecedence); /** * Specify whether ordering of inserts should be enabled. diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/Abstract.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/Abstract.java index 8f38da88eb..d398c4de92 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/Abstract.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/Abstract.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/CollectionClassification.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/CollectionClassification.java index 61028b5747..4ba3fd39d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/CollectionClassification.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/CollectionClassification.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/Extends.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/Extends.java index e38e92c59b..7e576d27cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/Extends.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/Extends.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/LimitedCollectionClassification.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/LimitedCollectionClassification.java index af76ab1054..72d86c0726 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/LimitedCollectionClassification.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/LimitedCollectionClassification.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java index fd824be4e4..89539da2fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java @@ -28,12 +28,13 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.internal.SessionFactoryImpl; import org.hibernate.loader.BatchFetchStyle; import org.hibernate.proxy.EntityNotFoundDelegate; -import org.hibernate.query.NullPrecedence; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.type.format.FormatMapper; +import jakarta.persistence.criteria.Nulls; + /** * @author Gail Badner * @author Steve Ebersole @@ -239,7 +240,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement } @Override - public SessionFactoryBuilder applyDefaultNullPrecedence(NullPrecedence nullPrecedence) { + public SessionFactoryBuilder applyDefaultNullPrecedence(Nulls nullPrecedence) { this.optionsBuilder.applyDefaultNullPrecedence( nullPrecedence ); return this; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java index 85008f7ccd..f92fe48306 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java @@ -59,7 +59,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode; import org.hibernate.query.criteria.ValueHandlingMode; import org.hibernate.query.hql.HqlTranslator; -import org.hibernate.query.NullPrecedence; +import org.hibernate.query.internal.NullPrecedenceHelper; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy; @@ -74,6 +74,8 @@ import org.hibernate.type.format.jackson.JacksonIntegration; import org.hibernate.type.format.jakartajson.JakartaJsonIntegration; import org.hibernate.type.format.jaxb.JaxbXmlFormatMapper; +import jakarta.persistence.criteria.Nulls; + import static org.hibernate.cfg.AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS; import static org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY; import static org.hibernate.cfg.AvailableSettings.ALLOW_UPDATE_OUTSIDE_TRANSACTION; @@ -203,7 +205,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { private int defaultBatchFetchSize; private Integer maximumFetchDepth; private boolean subselectFetchEnabled; - private NullPrecedence defaultNullPrecedence; + private Nulls defaultNullPrecedence; private boolean orderUpdatesEnabled; private boolean orderInsertsEnabled; private boolean collectionsInDefaultFetchGroupEnabled = true; @@ -388,13 +390,12 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.defaultNullPrecedence = (NullPrecedence) defaultNullPrecedence; } else if ( defaultNullPrecedence instanceof String ) { - this.defaultNullPrecedence = NullPrecedence.parse( (String) defaultNullPrecedence ); + this.defaultNullPrecedence = NullPrecedenceHelper.parse( (String) defaultNullPrecedence ); } else if ( defaultNullPrecedence != null ) { throw new IllegalArgumentException( "Configuration property " + DEFAULT_NULL_ORDERING + " value [" + defaultNullPrecedence + "] is not supported" ); } - this.orderUpdatesEnabled = getBoolean( ORDER_UPDATES, configurationSettings ); this.orderInsertsEnabled = getBoolean( ORDER_INSERTS, configurationSettings ); @@ -1046,7 +1047,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { } @Override - public NullPrecedence getDefaultNullPrecedence() { + public Nulls getDefaultNullPrecedence() { return defaultNullPrecedence; } @@ -1462,7 +1463,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.subselectFetchEnabled = subselectFetchEnabled; } - public void applyDefaultNullPrecedence(NullPrecedence nullPrecedence) { + public void applyDefaultNullPrecedence(Nulls nullPrecedence) { this.defaultNullPrecedence = nullPrecedence; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/Target.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/Target.java index 46479a34db..e1c694ca8b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/Target.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/Target.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java index d5de1b21bc..df1c81b2f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java @@ -211,8 +211,12 @@ public class MappingBinder extends AbstractBinder } final XMLEventReader hbmReader = new HbmEventReader( staxEventReader, xmlEventFactory ); - final JaxbHbmHibernateMapping hbmBindings = jaxb( hbmReader, MappingXsdSupport.INSTANCE.hbmXsd() - .getSchema(), hbmJaxbContext(), origin ); + final JaxbHbmHibernateMapping hbmBindings = jaxb( + hbmReader, + MappingXsdSupport.INSTANCE.hbmXsd().getSchema(), + hbmJaxbContext(), + origin + ); if ( optionsAccess.get().transformHbmMappings() ) { JaxbLogger.JAXB_LOGGER.tracef( "Performing on-the-fly hbm.xml -> mapping.xml transformation - %s ", origin ); @@ -230,8 +234,12 @@ public class MappingBinder extends AbstractBinder log.debugf( "Performing JAXB binding of orm.xml document : %s", origin.toString() ); final XMLEventReader reader = new MappingEventReader( staxEventReader, xmlEventFactory ); - final JaxbEntityMappingsImpl bindingRoot = jaxb( reader, MappingXsdSupport.latestDescriptor() - .getSchema(), mappingJaxbContext(), origin ); + final JaxbEntityMappingsImpl bindingRoot = jaxb( + reader, + MappingXsdSupport.latestDescriptor().getSchema(), + mappingJaxbContext(), + origin + ); //noinspection unchecked return new Binding<>( (X) bindingRoot, origin ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/MappingEventReader.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/MappingEventReader.java index 8545eb3a88..a6b9a1eca1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/MappingEventReader.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/MappingEventReader.java @@ -93,9 +93,10 @@ public class MappingEventReader extends EventReaderDelegate { } private Attribute mapAttribute(StartElement startElement, Attribute originalAttribute) { - // Here we look to see if this attribute is the JPA version attribute, and if so do 2 things: - // 1) validate its version attribute is valid - // 2) update its version attribute to the default version if not already + // Here we look to see if this attribute is the JPA version attribute, and if so do 3 things: + // 1) validate its version attribute is valid per our "latest XSD" + // 2) update its version attribute to the latest version if not already + // 3) if the latest XSD version is not in the XML list of valid versions, add it to avoid validation errors // // NOTE : atm this is a very simple check using just the attribute's local name // rather than checking its qualified name. It is possibly (though unlikely) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/FetchModeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/FetchModeMarshalling.java index 580b6b64b9..5cda5a6ab0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/FetchModeMarshalling.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/FetchModeMarshalling.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/LimitedCollectionClassificationMarshalling.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/LimitedCollectionClassificationMarshalling.java index 909a9d34d4..4f5d169f5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/LimitedCollectionClassificationMarshalling.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/internal/LimitedCollectionClassificationMarshalling.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.internal; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBaseAttributesContainer.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBaseAttributesContainer.java index e59f3d7765..0e8555e899 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBaseAttributesContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBaseAttributesContainer.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBasicMapping.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBasicMapping.java index 6380b7a10e..6fc7bab7a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBasicMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbBasicMapping.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbCheckConstraint.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbCheckConstraint.java index 075241091e..d261661f65 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbCheckConstraint.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbCheckConstraint.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddable.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddable.java index fa8b950ea4..78a441feda 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddable.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddable.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddedMapping.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddedMapping.java index 3894335bf3..0ecf127c90 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddedMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEmbeddedMapping.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java index fb26bb3724..6f865b8bac 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbLockableAttribute.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbLockableAttribute.java index a66eca61a6..9505f17645 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbLockableAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbLockableAttribute.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbMappedSuperclass.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbMappedSuperclass.java index 12031d41fa..43f57280cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbMappedSuperclass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbMappedSuperclass.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbNotFoundCapable.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbNotFoundCapable.java index 28b60b170e..a7f760113f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbNotFoundCapable.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbNotFoundCapable.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbSingularAttribute.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbSingularAttribute.java index aa467dc1a6..0f47727cb0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbSingularAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbSingularAttribute.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbTableMapping.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbTableMapping.java index 821339b827..e70f9d4732 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbTableMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbTableMapping.java @@ -1,8 +1,8 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.jaxb.mapping.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java index 18dfe2a11a..0133eb21fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java @@ -20,12 +20,13 @@ import org.hibernate.cache.spi.TimestampsCacheFactory; import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.loader.BatchFetchStyle; import org.hibernate.proxy.EntityNotFoundDelegate; -import org.hibernate.query.NullPrecedence; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.type.format.FormatMapper; +import jakarta.persistence.criteria.Nulls; + /** * Convenience base class for custom implementors of SessionFactoryBuilder, using delegation * @@ -187,7 +188,7 @@ public abstract class AbstractDelegatingSessionFactoryBuilder. */ package org.hibernate.internal.util; diff --git a/hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java b/hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java index acf502513e..11dcf62346 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java +++ b/hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java @@ -16,7 +16,10 @@ import jakarta.persistence.criteria.Nulls; * query result sets sorted by an {@code ORDER BY} clause. * * @author Lukasz Antoniak + * + * @deprecated Use Jakarta Persistence {@linkplain Nulls} instead. */ +@Deprecated public enum NullPrecedence { /** * Null precedence not specified. Relies on the RDBMS implementation. diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java index a2415b828e..4c99b04edc 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java @@ -24,11 +24,7 @@ import org.hibernate.Incubating; import org.hibernate.query.NullPrecedence; import org.hibernate.query.SortDirection; import org.hibernate.query.sqm.FrameKind; -import org.hibernate.query.sqm.SetOperator; -import org.hibernate.query.sqm.SqmQuerySource; import org.hibernate.query.sqm.TemporalUnit; -import org.hibernate.query.sqm.tree.select.SqmQueryGroup; -import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.AbstractQuery; @@ -188,16 +184,15 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder { JpaCriteriaQuery union(CriteriaQuery left, CriteriaQuery right); @Override - JpaCriteriaQuery unionAll(CriteriaQuery left, CriteriaQuery right); + default JpaCriteriaQuery unionAll(CriteriaQuery left, CriteriaQuery right) { + return null; + } default JpaSubQuery union(Subquery query1, Subquery... queries) { return union( false, query1, queries ); } - default JpaSubQuery union(boolean all, Subquery query1, Subquery... queries) { - assert query1 instanceof SqmSelectStatement; - return null; - } + JpaSubQuery union(boolean all, Subquery query1, Subquery... queries); @Override JpaCriteriaQuery intersect(CriteriaQuery left, CriteriaQuery right); diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java index 24c57da4b7..b1bf710210 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java @@ -865,7 +865,7 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde @Override public JpaPredicate and(List restrictions) { - return null; + return criteriaBuilder.and( restrictions ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/NullPrecedenceHelper.java b/hibernate-core/src/main/java/org/hibernate/query/internal/NullPrecedenceHelper.java new file mode 100644 index 0000000000..b36b54f67b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/NullPrecedenceHelper.java @@ -0,0 +1,93 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.query.internal; + +import org.hibernate.AssertionFailure; +import org.hibernate.dialect.NullOrdering; +import org.hibernate.query.SortDirection; + +import jakarta.persistence.criteria.Nulls; + +/** + * @author Steve Ebersole + */ +public class NullPrecedenceHelper { + + /** + * Is this null precedence the default for the given sort order and null ordering. + */ + public static boolean isDefaultOrdering( + Nulls precedence, + SortDirection sortOrder, + NullOrdering nullOrdering) { + switch (precedence) { + case NONE: + return true; + case FIRST: + switch ( nullOrdering ) { + case FIRST: + return true; + case LAST: + return false; + case SMALLEST: + return sortOrder == SortDirection.ASCENDING; + case GREATEST: + return sortOrder == SortDirection.DESCENDING; + default: + throw new AssertionFailure( "Unrecognized NullOrdering"); + } + case LAST: + switch ( nullOrdering ) { + case LAST: + return true; + case FIRST: + return false; + case SMALLEST: + return sortOrder == SortDirection.DESCENDING; + case GREATEST: + return sortOrder == SortDirection.ASCENDING; + default: + throw new AssertionFailure("Unrecognized NullOrdering"); + } + default: + throw new AssertionFailure("Unrecognized NullPrecedence"); + } + } + + /** + * Interprets a string representation of a NullPrecedence, returning {@code null} by default. For + * alternative default handling, see {@link #parse(String, Nulls)} + * + * @param name The String representation to interpret + * + * @return The recognized NullPrecedence, or {@code null} + */ + public static Nulls parse(String name) { + for ( Nulls value : Nulls.values() ) { + if ( value.name().equalsIgnoreCase( name ) ) { + return value; + } + } + return null; + } + + /** + * Interprets a string representation of a NullPrecedence, returning the specified default if not recognized. + * + * @param name The String representation to interpret + * @param defaultValue The default value to use + * + * @return The recognized NullPrecedence, or {@code defaultValue}. + */ + public static Nulls parse(String name, Nulls defaultValue) { + final Nulls value = parse( name ); + return value != null ? value : defaultValue; + } + + private NullPrecedenceHelper() { + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 9f721cccfe..a033ccfb14 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -792,13 +792,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public JpaCompoundSelection tuple(List> selections) { - checkMultiselect( selections ); - //noinspection unchecked - return new SqmJpaCompoundSelection<>( - (List>) selections, - getTypeConfiguration().getJavaTypeRegistry().getDescriptor( Tuple.class ), - this - ); + return null; } @Override @@ -2227,7 +2221,15 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, @Override public SqmPredicate or(List restrictions) { - return null; + if ( restrictions == null || restrictions.isEmpty() ) { + return disjunction(); + } + + final List predicates = new ArrayList<>( restrictions.size() ); + for ( Predicate expression : restrictions ) { + predicates.add( (SqmPredicate) expression ); + } + return new SqmJunctionPredicate( Predicate.BooleanOperator.OR, predicates, this ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java index 11a97f6e91..fcf3b74091 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmStatement.java @@ -9,12 +9,16 @@ package org.hibernate.query.sqm.tree; import java.util.Collections; import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmQuerySource; import org.hibernate.query.sqm.internal.ParameterCollector; import org.hibernate.query.sqm.internal.SqmUtil; import org.hibernate.query.sqm.tree.expression.SqmParameter; +import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter; + +import jakarta.persistence.criteria.ParameterExpression; import static org.hibernate.query.sqm.tree.jpa.ParameterCollector.collectParameters; @@ -82,4 +86,17 @@ public abstract class AbstractSqmStatement extends AbstractSqmNode implements public ParameterResolutions resolveParameters() { return SqmUtil.resolveParameters( this ); } + + @Override + public Set> getParameters() { + // At this level, the number of parameters may still be growing as + // nodes are added to the Criteria - so we re-calculate this every + // time. + // + // for a "finalized" set of parameters, use `#resolveParameters` instead + assert getQuerySource() == SqmQuerySource.CRITERIA; + return getSqmParameters().stream() + .filter( parameterExpression -> !( parameterExpression instanceof ValueBindJpaCriteriaParameter ) ) + .collect( Collectors.toSet() ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/delete/SqmDeleteStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/delete/SqmDeleteStatement.java index 1214745a5b..c082a0b953 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/delete/SqmDeleteStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/delete/SqmDeleteStatement.java @@ -146,17 +146,4 @@ public class SqmDeleteStatement public Subquery subquery(EntityType type) { throw new UnsupportedOperationException( "DELETE query cannot be sub-query" ); } - - @Override - public Set> getParameters() { - // At this level, the number of parameters may still be growing as - // nodes are added to the Criteria - so we re-calculate this every - // time. - // - // for a "finalized" set of parameters, use `#resolveParameters` instead - assert getQuerySource() == SqmQuerySource.CRITERIA; - return getSqmParameters().stream() - .filter( parameterExpression -> !( parameterExpression instanceof ValueBindJpaCriteriaParameter ) ) - .collect( Collectors.toSet() ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java index ff8ce81b97..b25c661d75 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmFrom.java @@ -28,7 +28,6 @@ import org.hibernate.query.SemanticException; import org.hibernate.query.criteria.JpaCrossJoin; import org.hibernate.query.criteria.JpaCteCriteria; import org.hibernate.query.criteria.JpaDerivedJoin; -import org.hibernate.query.criteria.JpaEntityJoin; import org.hibernate.query.criteria.JpaPath; import org.hibernate.query.criteria.JpaSelection; import org.hibernate.query.hql.spi.SqmCreationState; @@ -319,7 +318,7 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements @Override public SqmEntityJoin join(Class targetEntityClass, SqmJoinType joinType) { - return join( nodeBuilder().getJpaMetamodel().entity( targetEntityClass ) ); + return join( nodeBuilder().getJpaMetamodel().entity( targetEntityClass ), joinType ); } @Override @@ -544,22 +543,22 @@ public abstract class AbstractSqmFrom extends AbstractSqmPath implements } @Override - public JpaEntityJoin join(Class entityJavaType) { + public SqmEntityJoin join(Class entityJavaType) { return join( nodeBuilder().getDomainModel().entity( entityJavaType ) ); } @Override - public JpaEntityJoin join(EntityType entityType) { + public SqmEntityJoin join(EntityType entityType) { return join( entityType, JoinType.INNER ); } @Override - public JpaEntityJoin join(Class entityJavaType, JoinType joinType) { + public SqmEntityJoin join(Class entityJavaType, JoinType joinType) { return join( nodeBuilder().getDomainModel().entity( entityJavaType ), joinType ); } @Override - public JpaEntityJoin join(EntityType entity, JoinType joinType) { + public SqmEntityJoin join(EntityType entity, JoinType joinType) { //noinspection unchecked final SqmEntityJoin join = new SqmEntityJoin<>( entity, null, joinType, (SqmRoot) findRoot() ); addSqmJoin( join ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java index e193017ac3..2e7124287b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmJoin.java @@ -13,6 +13,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmJoinType; +import org.hibernate.query.sqm.tree.from.SqmEntityJoin; import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.query.sqm.tree.from.SqmJoin; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; @@ -136,4 +137,14 @@ public abstract class AbstractSqmJoin extends AbstractSqmFrom implem applyRestriction( nodeBuilder().wrap( restrictions ) ); return this; } + + @Override + public SqmEntityJoin join(Class targetEntityClass) { + return super.join( targetEntityClass, joinType ); + } + + @Override + public SqmEntityJoin join(Class targetEntityClass, SqmJoinType joinType) { + return super.join( targetEntityClass, joinType ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java index 67b02b6370..20ac4dd49f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java @@ -19,7 +19,7 @@ import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedBagJoin extends SqmBagJoin implements SqmCorrelation { +public class SqmCorrelatedBagJoin extends SqmBagJoin implements SqmCorrelatedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmBagJoin correlationParent; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedEntityJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedEntityJoin.java index 39d13254b5..7f86f21c07 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedEntityJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedEntityJoin.java @@ -18,7 +18,7 @@ import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedEntityJoin extends SqmEntityJoin implements SqmCorrelation { +public class SqmCorrelatedEntityJoin extends SqmEntityJoin implements SqmCorrelatedSingularValuedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmEntityJoin correlationParent; @@ -98,6 +98,11 @@ public class SqmCorrelatedEntityJoin extends SqmEntityJoin implements return correlatedRootJoin; } + @Override + public SqmCorrelatedEntityJoin createCorrelation() { + return new SqmCorrelatedEntityJoin<>( this ); + } + @Override public SqmCorrelatedEntityJoin makeCopy(SqmCreationProcessingState creationProcessingState) { final SqmPathRegistry pathRegistry = creationProcessingState.getPathRegistry(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedJoin.java new file mode 100644 index 0000000000..3cf407433f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedJoin.java @@ -0,0 +1,15 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.query.sqm.tree.domain; + +import org.hibernate.query.sqm.tree.from.SqmJoin; + +/** + * @author Steve Ebersole + */ +public interface SqmCorrelatedJoin extends SqmCorrelation, SqmJoin { +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java index 75d8f8ab61..f9df597c84 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java @@ -19,7 +19,7 @@ import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedListJoin extends SqmListJoin implements SqmCorrelation { +public class SqmCorrelatedListJoin extends SqmListJoin implements SqmCorrelatedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmListJoin correlationParent; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java index 10329a1563..feb940e957 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java @@ -19,7 +19,7 @@ import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedMapJoin extends SqmMapJoin implements SqmCorrelation { +public class SqmCorrelatedMapJoin extends SqmMapJoin implements SqmCorrelatedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmMapJoin correlationParent; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedPluralPartJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedPluralPartJoin.java index c222a606c1..87e6ca3eb5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedPluralPartJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedPluralPartJoin.java @@ -9,13 +9,12 @@ package org.hibernate.query.sqm.tree.domain; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmJoinType; -import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedPluralPartJoin extends SqmPluralPartJoin implements SqmCorrelation { +public class SqmCorrelatedPluralPartJoin extends SqmPluralPartJoin implements SqmCorrelatedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmPluralPartJoin correlationParent; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java index cf9358b1c9..deb324c2e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java @@ -19,7 +19,7 @@ import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedSetJoin extends SqmSetJoin implements SqmCorrelation { +public class SqmCorrelatedSetJoin extends SqmSetJoin implements SqmCorrelatedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmSetJoin correlationParent; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java index 0baad24fd7..1609f299e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java @@ -19,7 +19,7 @@ import org.hibernate.query.sqm.tree.from.SqmRoot; /** * @author Christian Beikov */ -public class SqmCorrelatedSingularJoin extends SqmSingularJoin implements SqmCorrelation { +public class SqmCorrelatedSingularJoin extends SqmSingularJoin implements SqmCorrelatedSingularValuedJoin { private final SqmCorrelatedRootJoin correlatedRootJoin; private final SqmSingularJoin correlationParent; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularValuedJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularValuedJoin.java new file mode 100644 index 0000000000..65079fde14 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularValuedJoin.java @@ -0,0 +1,13 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.query.sqm.tree.domain; + +/** + * @author Steve Ebersole + */ +public interface SqmCorrelatedSingularValuedJoin extends SqmSingularValuedJoin, SqmCorrelatedJoin { +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java index 516ad1175b..0da8eff6a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java @@ -29,7 +29,7 @@ import org.hibernate.spi.NavigablePath; /** * @author Steve Ebersole */ -public class SqmSingularJoin extends AbstractSqmAttributeJoin { +public class SqmSingularJoin extends AbstractSqmAttributeJoin implements SqmSingularValuedJoin { public SqmSingularJoin( SqmFrom lhs, SingularPersistentAttribute joinedNavigable, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularValuedJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularValuedJoin.java new file mode 100644 index 0000000000..8b5023586f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularValuedJoin.java @@ -0,0 +1,16 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.query.sqm.tree.domain; + +import org.hibernate.query.sqm.tree.from.SqmJoin; + +/** + * @author Steve Ebersole + */ +public interface SqmSingularValuedJoin extends SqmJoin { + SqmCorrelatedSingularValuedJoin createCorrelation(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java index e653333645..e053642550 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedRoot.java @@ -17,7 +17,7 @@ import org.hibernate.spi.NavigablePath; /** * @author Steve Ebersole */ -public class SqmTreatedRoot extends SqmRoot implements SqmTreatedPath { +public class SqmTreatedRoot extends SqmRoot implements SqmTreatedFrom { private final SqmRoot wrappedPath; private final EntityDomainType treatTarget; @@ -53,7 +53,7 @@ public class SqmTreatedRoot extends SqmRoot implements SqmTre } @Override - public SqmRoot copy(SqmCopyContext context) { + public SqmTreatedRoot copy(SqmCopyContext context) { final SqmTreatedRoot existing = context.getCopy( this ); if ( existing != null ) { return existing; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java index 67b9a02148..8c57914dde 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmEntityJoin.java @@ -20,6 +20,7 @@ import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.AbstractSqmJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedEntityJoin; +import org.hibernate.query.sqm.tree.domain.SqmSingularValuedJoin; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedEntityJoin; import org.hibernate.query.sqm.tree.expression.SqmExpression; @@ -33,7 +34,7 @@ import jakarta.persistence.metamodel.EntityType; /** * @author Steve Ebersole */ -public class SqmEntityJoin extends AbstractSqmJoin implements JpaEntityJoin { +public class SqmEntityJoin extends AbstractSqmJoin implements SqmSingularValuedJoin, JpaEntityJoin { private final SqmRoot sqmRoot; public SqmEntityJoin( @@ -213,4 +214,6 @@ public class SqmEntityJoin extends AbstractSqmJoin implements JpaEntit pathRegistry.findFromByPath( getRoot().getNavigablePath() ) ); } + + } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java index c4c6ba988d..f040621ad9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmFrom.java @@ -17,6 +17,7 @@ import jakarta.persistence.metamodel.SetAttribute; import jakarta.persistence.metamodel.SingularAttribute; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.query.criteria.JpaEntityJoin; import org.hibernate.query.criteria.JpaFrom; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.SqmCopyContext; @@ -92,6 +93,12 @@ public interface SqmFrom extends SqmVisitableNode, SqmPath, JpaFrom getCorrelationParent(); + @Override + SqmEntityJoin join(Class entityClass); + + @Override + SqmEntityJoin join(Class entityClass, JoinType joinType); + @Override SqmSingularJoin join(SingularAttribute attribute); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmJoin.java index 2d85143510..e02c5d7dd0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmJoin.java @@ -9,13 +9,29 @@ package org.hibernate.query.sqm.tree.from; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.JoinType; import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Subquery; +import jakarta.persistence.metamodel.CollectionAttribute; +import jakarta.persistence.metamodel.EntityType; +import jakarta.persistence.metamodel.ListAttribute; +import jakarta.persistence.metamodel.MapAttribute; +import jakarta.persistence.metamodel.SetAttribute; +import jakarta.persistence.metamodel.SingularAttribute; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.query.criteria.JpaCrossJoin; +import org.hibernate.query.criteria.JpaCteCriteria; +import org.hibernate.query.criteria.JpaDerivedJoin; +import org.hibernate.query.criteria.JpaEntityJoin; import org.hibernate.query.criteria.JpaExpression; import org.hibernate.query.criteria.JpaJoin; import org.hibernate.query.criteria.JpaPredicate; import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmJoinType; +import org.hibernate.query.sqm.tree.domain.SqmBagJoin; +import org.hibernate.query.sqm.tree.domain.SqmListJoin; +import org.hibernate.query.sqm.tree.domain.SqmMapJoin; +import org.hibernate.query.sqm.tree.domain.SqmSetJoin; +import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; import org.hibernate.query.sqm.tree.domain.SqmTreatedJoin; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; @@ -110,4 +126,102 @@ public interface SqmJoin extends SqmFrom, JpaJoin { ) ); return this; } + + @Override + default JpaEntityJoin join(Class entityJavaType, SqmJoinType joinType) { + return SqmFrom.super.join( entityJavaType, joinType ); + } + + @Override + JpaJoin join(EntityType entity); + + @Override + JpaJoin join(EntityType entity, JoinType joinType); + + @Override + JpaEntityJoin join(EntityDomainType entity); + + @Override + JpaEntityJoin join(EntityDomainType entity, SqmJoinType joinType); + + @Override + JpaDerivedJoin join(Subquery subquery); + + @Override + JpaDerivedJoin join(Subquery subquery, SqmJoinType joinType); + + @Override + JpaDerivedJoin joinLateral(Subquery subquery); + + @Override + JpaDerivedJoin joinLateral(Subquery subquery, SqmJoinType joinType); + + @Override + JpaDerivedJoin join(Subquery subquery, SqmJoinType joinType, boolean lateral); + + @Override + JpaJoin join(JpaCteCriteria cte); + + @Override + JpaJoin join(JpaCteCriteria cte, SqmJoinType joinType); + + @Override + JpaCrossJoin crossJoin(Class entityJavaType); + + @Override + JpaCrossJoin crossJoin(EntityDomainType entity); + + @Override + SqmSingularJoin join(SingularAttribute attribute); + + @Override + SqmSingularJoin join(SingularAttribute attribute, JoinType jt); + + @Override + SqmBagJoin join(CollectionAttribute attribute); + + @Override + SqmBagJoin join(CollectionAttribute attribute, JoinType jt); + + @Override + SqmSetJoin join(SetAttribute set); + + @Override + SqmSetJoin join(SetAttribute set, JoinType jt); + + @Override + SqmListJoin join(ListAttribute list); + + @Override + SqmListJoin join(ListAttribute list, JoinType jt); + + @Override + SqmMapJoin join(MapAttribute map); + + @Override + SqmMapJoin join(MapAttribute map, JoinType jt); + + @Override + SqmBagJoin joinCollection(String attributeName); + + @Override + SqmBagJoin joinCollection(String attributeName, JoinType jt); + + @Override + SqmSetJoin joinSet(String attributeName); + + @Override + SqmSetJoin joinSet(String attributeName, JoinType jt); + + @Override + SqmListJoin joinList(String attributeName); + + @Override + SqmListJoin joinList(String attributeName, JoinType jt); + + @Override + SqmMapJoin joinMap(String attributeName); + + @Override + SqmMapJoin joinMap(String attributeName, JoinType jt); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java index 81585cb4e3..d358cd62a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java @@ -25,12 +25,12 @@ public class SqmSortSpecification implements JpaOrder { private final SqmExpression sortExpression; private final SortDirection sortOrder; private final boolean ignoreCase; - private NullPrecedence nullPrecedence; + private Nulls nullPrecedence; public SqmSortSpecification( @SuppressWarnings("rawtypes") SqmExpression sortExpression, SortDirection sortOrder, - NullPrecedence nullPrecedence) { + Nulls nullPrecedence) { this( sortExpression, sortOrder, nullPrecedence, false ); } @@ -48,14 +48,25 @@ public class SqmSortSpecification implements JpaOrder { this.ignoreCase = ignoreCase; } + /** + * @deprecated Use {@link SqmSortSpecification#SqmSortSpecification(SqmExpression, SortDirection, Nulls)} instead + */ + @Deprecated + public SqmSortSpecification( + @SuppressWarnings("rawtypes") SqmExpression sortExpression, + SortDirection sortOrder, + NullPrecedence nullPrecedence) { + this( sortExpression, sortOrder, nullPrecedence.getJpaValue() ); + } + @SuppressWarnings("rawtypes") public SqmSortSpecification(SqmExpression sortExpression) { - this( sortExpression, SortDirection.ASCENDING, NullPrecedence.NONE ); + this( sortExpression, SortDirection.ASCENDING, Nulls.NONE ); } @SuppressWarnings("rawtypes") public SqmSortSpecification(SqmExpression sortExpression, SortDirection sortOrder) { - this( sortExpression, sortOrder, NullPrecedence.NONE ); + this( sortExpression, sortOrder, Nulls.NONE ); } public SqmSortSpecification copy(SqmCopyContext context) { @@ -81,13 +92,13 @@ public class SqmSortSpecification implements JpaOrder { @Override public JpaOrder nullPrecedence(Nulls nullPrecedence) { - this.nullPrecedence = NullPrecedence.fromJpaValue( nullPrecedence ); + this.nullPrecedence = nullPrecedence; return this; } @Override public Nulls getNullPrecedence() { - return nullPrecedence.getJpaValue(); + return nullPrecedence; } @Override @@ -111,7 +122,7 @@ public class SqmSortSpecification implements JpaOrder { if ( sortOrder == SortDirection.DESCENDING ) { sb.append( " desc" ); if ( nullPrecedence != null ) { - if ( nullPrecedence == NullPrecedence.FIRST ) { + if ( nullPrecedence == Nulls.FIRST ) { sb.append( " nulls first" ); } else { @@ -121,7 +132,7 @@ public class SqmSortSpecification implements JpaOrder { } else if ( nullPrecedence != null ) { sb.append( " asc" ); - if ( nullPrecedence == NullPrecedence.FIRST ) { + if ( nullPrecedence == Nulls.FIRST ) { sb.append( " nulls first" ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java index 9cf95059f8..1b5cdeb755 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java @@ -36,16 +36,18 @@ import org.hibernate.query.sqm.tree.domain.SqmBagJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedBagJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedCrossJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedEntityJoin; +import org.hibernate.query.sqm.tree.domain.SqmCorrelatedJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedListJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedMapJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedRoot; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedSetJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedSingularJoin; +import org.hibernate.query.sqm.tree.domain.SqmCorrelatedSingularValuedJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelation; import org.hibernate.query.sqm.tree.domain.SqmListJoin; import org.hibernate.query.sqm.tree.domain.SqmMapJoin; import org.hibernate.query.sqm.tree.domain.SqmSetJoin; -import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; +import org.hibernate.query.sqm.tree.domain.SqmSingularValuedJoin; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; @@ -477,7 +479,7 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele } @Override - public SqmAttributeJoin correlate(Join join) { + public SqmCorrelatedJoin correlate(Join join) { if ( join instanceof PluralJoin ) { final PluralJoin pluralJoin = (PluralJoin) join; switch ( pluralJoin.getModel().getCollectionType() ) { @@ -491,41 +493,41 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele return correlate( (MapJoin) join ); } } - final SqmCorrelatedSingularJoin correlated = ( (SqmSingularJoin) join ).createCorrelation(); + final SqmCorrelatedSingularValuedJoin correlated = ( (SqmSingularValuedJoin) join ).createCorrelation(); getQuerySpec().addRoot( correlated.getCorrelatedRoot() ); return correlated; } @Override - public SqmBagJoin correlate(CollectionJoin parentCollection) { + public SqmCorrelatedBagJoin correlate(CollectionJoin parentCollection) { final SqmCorrelatedBagJoin correlated = ( (SqmBagJoin) parentCollection ).createCorrelation(); getQuerySpec().addRoot( correlated.getCorrelatedRoot() ); return correlated; } @Override - public SqmSetJoin correlate(SetJoin parentSet) { + public SqmCorrelatedSetJoin correlate(SetJoin parentSet) { final SqmCorrelatedSetJoin correlated = ( (SqmSetJoin) parentSet ).createCorrelation(); getQuerySpec().addRoot( correlated.getCorrelatedRoot() ); return correlated; } @Override - public SqmListJoin correlate(ListJoin parentList) { + public SqmCorrelatedListJoin correlate(ListJoin parentList) { final SqmCorrelatedListJoin correlated = ( (SqmListJoin) parentList ).createCorrelation(); getQuerySpec().addRoot( correlated.getCorrelatedRoot() ); return correlated; } @Override - public SqmMapJoin correlate(MapJoin parentMap) { + public SqmCorrelatedMapJoin correlate(MapJoin parentMap) { final SqmCorrelatedMapJoin correlated = ( (SqmMapJoin) parentMap ).createCorrelation(); getQuerySpec().addRoot( correlated.getCorrelatedRoot() ); return correlated; } @Override - public SqmCrossJoin correlate(JpaCrossJoin parentCrossJoin) { + public SqmCorrelatedCrossJoin correlate(JpaCrossJoin parentCrossJoin) { final SqmCorrelatedCrossJoin correlated = ((SqmCrossJoin) parentCrossJoin).createCorrelation(); getQuerySpec().addRoot( correlated.getCorrelatedRoot() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/update/SqmUpdateStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/update/SqmUpdateStatement.java index 976bc6b636..ced72d33b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/update/SqmUpdateStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/update/SqmUpdateStatement.java @@ -264,11 +264,6 @@ public class SqmUpdateStatement return new SqmSubQuery<>( this, type, nodeBuilder() ); } - @Override - public Set> getParameters() { - return null; - } - public void applyAssignment(SqmPath targetPath, SqmExpression value) { applyAssignment( new SqmAssignment<>( targetPath, value ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index 7c13e9b694..7e15d8894b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -28,8 +28,8 @@ import org.hibernate.Internal; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.QueryException; -import org.hibernate.dialect.DmlTargetColumnQualifierSupport; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.DmlTargetColumnQualifierSupport; import org.hibernate.dialect.RowLockStrategy; import org.hibernate.dialect.SelectItemReferenceStrategy; import org.hibernate.engine.jdbc.Size; @@ -61,8 +61,10 @@ import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.persister.entity.Loadable; import org.hibernate.persister.internal.SqlFragmentPredicate; import org.hibernate.query.IllegalQueryOperationException; +import org.hibernate.query.NullPrecedence; import org.hibernate.query.ReturnableType; import org.hibernate.query.SortDirection; +import org.hibernate.query.results.TableGroupImpl; import org.hibernate.query.spi.Limit; import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.sqm.BinaryArithmeticOperator; @@ -71,7 +73,6 @@ import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.query.sqm.FrameExclusion; import org.hibernate.query.sqm.FrameKind; import org.hibernate.query.sqm.FrameMode; -import org.hibernate.query.NullPrecedence; import org.hibernate.query.sqm.SetOperator; import org.hibernate.query.sqm.UnaryArithmeticOperator; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; @@ -227,6 +228,8 @@ import org.hibernate.type.descriptor.sql.DdlType; import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.criteria.Nulls; + import static org.hibernate.persister.entity.DiscriminatorHelper.jdbcLiteral; import static org.hibernate.query.sqm.BinaryArithmeticOperator.DIVIDE_PORTABLE; import static org.hibernate.query.sqm.TemporalUnit.NANOSECOND; @@ -2585,12 +2588,12 @@ public abstract class AbstractSqlAstTranslator implemen appendSql( searchBySpecification.getCteColumn().getColumnExpression() ); final SortDirection sortOrder = searchBySpecification.getSortOrder(); if ( sortOrder != null ) { - NullPrecedence nullPrecedence = searchBySpecification.getNullPrecedence(); - if ( nullPrecedence == null || nullPrecedence == NullPrecedence.NONE ) { + Nulls nullPrecedence = searchBySpecification.getNullPrecedence(); + if ( nullPrecedence == null || nullPrecedence == Nulls.NONE ) { nullPrecedence = sessionFactory.getSessionFactoryOptions().getDefaultNullPrecedence(); } - final boolean renderNullPrecedence = nullPrecedence != null && - !nullPrecedence.isDefaultOrdering( sortOrder, dialect.getNullOrdering() ); + final boolean renderNullPrecedence = nullPrecedence != null + && !NullPrecedenceHelper.isDefaultOrdering( nullPrecedence, sortOrder, dialect.getNullOrdering() ); if ( sortOrder == SortDirection.DESCENDING ) { appendSql( " desc" ); } @@ -2598,7 +2601,7 @@ public abstract class AbstractSqlAstTranslator implemen appendSql( " asc" ); } if ( renderNullPrecedence ) { - if ( searchBySpecification.getNullPrecedence() == NullPrecedence.FIRST ) { + if ( searchBySpecification.getNullPrecedence() == Nulls.FIRST ) { appendSql( " nulls first" ); } else { @@ -2722,7 +2725,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2754,7 +2757,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2781,7 +2784,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2803,7 +2806,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2864,7 +2867,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2902,7 +2905,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2941,7 +2944,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -2980,7 +2983,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( searchBySpecification.getSortOrder() == SortDirection.DESCENDING ) { throw new IllegalArgumentException( "Can't emulate search clause for descending search specifications" ); } - if ( searchBySpecification.getNullPrecedence() != NullPrecedence.NONE ) { + if ( searchBySpecification.getNullPrecedence() != Nulls.NONE ) { throw new IllegalArgumentException( "Can't emulate search clause for search specifications with explicit null precedence" ); } final int selectionIndex = currentCteStatement.getCteTable() @@ -4380,7 +4383,7 @@ public abstract class AbstractSqlAstTranslator implemen @Override public void visitSortSpecification(SortSpecification sortSpecification) { final Expression sortExpression = sortSpecification.getSortExpression(); - final NullPrecedence nullPrecedence = sortSpecification.getHibernateNullPrecedence(); + final Nulls nullPrecedence = sortSpecification.getNullPrecedence(); final SortDirection sortOrder = sortSpecification.getSortOrder(); final boolean ignoreCase = sortSpecification.isIgnoreCase(); final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple( sortExpression ); @@ -4400,13 +4403,13 @@ public abstract class AbstractSqlAstTranslator implemen protected void visitSortSpecification( Expression sortExpression, SortDirection sortOrder, - NullPrecedence nullPrecedence, + Nulls nullPrecedence, boolean ignoreCase) { - if ( nullPrecedence == null || nullPrecedence == NullPrecedence.NONE ) { + if ( nullPrecedence == null || nullPrecedence == Nulls.NONE ) { nullPrecedence = sessionFactory.getSessionFactoryOptions().getDefaultNullPrecedence(); } - final boolean renderNullPrecedence = nullPrecedence != null && - !nullPrecedence.isDefaultOrdering( sortOrder, dialect.getNullOrdering() ); + final boolean renderNullPrecedence = nullPrecedence != null + && !NullPrecedenceHelper.isDefaultOrdering( nullPrecedence, sortOrder, dialect.getNullOrdering() ); final boolean supportsNullPrecedence = renderNullPrecedence && supportsNullPrecedence(); if ( renderNullPrecedence && !supportsNullPrecedence ) { emulateSortSpecificationNullPrecedence( sortExpression, nullPrecedence ); @@ -4423,7 +4426,7 @@ public abstract class AbstractSqlAstTranslator implemen if ( renderNullPrecedence && supportsNullPrecedence ) { appendSql( " nulls " ); - appendSql( nullPrecedence == NullPrecedence.LAST ? "last" : "first" ); + appendSql( nullPrecedence == Nulls.LAST ? "last" : "first" ); } } @@ -4443,18 +4446,30 @@ public abstract class AbstractSqlAstTranslator implemen if ( ignoreCase ) { appendSql( CLOSE_PARENTHESIS ); } + + if ( sortOrder == SortDirection.DESCENDING ) { + appendSql( " desc" ); + } + else if ( sortOrder == SortDirection.ASCENDING && renderNullPrecedence && supportsNullPrecedence ) { + appendSql( " asc" ); + } + + if ( renderNullPrecedence && supportsNullPrecedence ) { + appendSql( " nulls " ); + appendSql( nullPrecedence == Nulls.LAST ? "last" : "first" ); + } } protected boolean supportsNullPrecedence() { return dialect.supportsNullPrecedence(); } - protected void emulateSortSpecificationNullPrecedence(Expression sortExpression, NullPrecedence nullPrecedence) { + protected void emulateSortSpecificationNullPrecedence(Expression sortExpression, Nulls nullPrecedence) { // TODO: generate "virtual" select items and use them here positionally appendSql( "case when (" ); resolveAliasedExpression( sortExpression ).accept( this ); appendSql( ") is null then " ); - if ( nullPrecedence == NullPrecedence.FIRST ) { + if ( nullPrecedence == Nulls.FIRST ) { appendSql( "0 else 1" ); } else { @@ -6735,28 +6750,28 @@ public abstract class AbstractSqlAstTranslator implemen } private boolean isNullsFirst(SortSpecification sortSpecification) { - NullPrecedence nullPrecedence = sortSpecification.getHibernateNullPrecedence(); - if ( nullPrecedence == null || nullPrecedence == NullPrecedence.NONE ) { + Nulls nullPrecedence = sortSpecification.getNullPrecedence(); + if ( nullPrecedence == null || nullPrecedence == Nulls.NONE ) { switch ( dialect.getNullOrdering() ) { case FIRST: - nullPrecedence = NullPrecedence.FIRST; + nullPrecedence = Nulls.FIRST; break; case LAST: - nullPrecedence = NullPrecedence.LAST; + nullPrecedence = Nulls.LAST; break; case SMALLEST: nullPrecedence = sortSpecification.getSortOrder() == SortDirection.ASCENDING - ? NullPrecedence.FIRST - : NullPrecedence.LAST; + ? Nulls.FIRST + : Nulls.LAST; break; case GREATEST: nullPrecedence = sortSpecification.getSortOrder() == SortDirection.DESCENDING - ? NullPrecedence.FIRST - : NullPrecedence.LAST; + ? Nulls.FIRST + : Nulls.LAST; break; } } - return nullPrecedence == NullPrecedence.FIRST; + return nullPrecedence == Nulls.FIRST; } private int getSortSelectionIndex(QuerySpec querySpec, SortSpecification sortSpecification) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java index c7a92871ba..d38b478a0b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java @@ -9,20 +9,30 @@ package org.hibernate.sql.ast.tree.cte; import org.hibernate.query.NullPrecedence; import org.hibernate.query.SortDirection; +import jakarta.persistence.criteria.Nulls; + /** * @author Christian Beikov */ public class SearchClauseSpecification { private final CteColumn cteColumn; private final SortDirection sortOrder; - private final NullPrecedence nullPrecedence; + private final Nulls nullPrecedence; - public SearchClauseSpecification(CteColumn cteColumn, SortDirection sortOrder, NullPrecedence nullPrecedence) { + public SearchClauseSpecification(CteColumn cteColumn, SortDirection sortOrder, Nulls nullPrecedence) { this.cteColumn = cteColumn; this.sortOrder = sortOrder; this.nullPrecedence = nullPrecedence; } + /** + * @deprecated Use {@link SearchClauseSpecification#SearchClauseSpecification(CteColumn,SortDirection,Nulls)} instead + */ + @Deprecated + public SearchClauseSpecification(CteColumn cteColumn, SortDirection sortOrder, NullPrecedence nullPrecedence) { + this( cteColumn, sortOrder, nullPrecedence.getJpaValue() ); + } + public CteColumn getCteColumn() { return cteColumn; } @@ -31,7 +41,7 @@ public class SearchClauseSpecification { return sortOrder; } - public NullPrecedence getNullPrecedence() { + public Nulls getNullPrecedence() { return nullPrecedence; } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java index 81b50f846e..306004c4a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java @@ -20,18 +20,18 @@ import jakarta.persistence.criteria.Nulls; public class SortSpecification implements SqlAstNode { private final Expression sortExpression; private final SortDirection sortOrder; - private final NullPrecedence nullPrecedence; + private final Nulls nullPrecedence; private final boolean ignoreCase; public SortSpecification(Expression sortExpression, SortDirection sortOrder) { - this( sortExpression, sortOrder, NullPrecedence.NONE ); + this( sortExpression, sortOrder, Nulls.NONE, false ); } public SortSpecification(Expression sortExpression, SortDirection sortOrder, NullPrecedence nullPrecedence) { - this(sortExpression, sortOrder, nullPrecedence, false); + this( sortExpression, sortOrder, nullPrecedence.getJpaValue(), false ); } - public SortSpecification(Expression sortExpression, SortDirection sortOrder, NullPrecedence nullPrecedence, boolean ignoreCase) { + public SortSpecification(Expression sortExpression, SortDirection sortOrder, Nulls nullPrecedence, boolean ignoreCase) { assert sortExpression != null; assert sortOrder != null; assert nullPrecedence != null; @@ -41,10 +41,6 @@ public class SortSpecification implements SqlAstNode { this.ignoreCase = ignoreCase; } - public SortSpecification(Expression sortExpression, SortDirection sortOrder, Nulls nullPrecedence) { - this( sortExpression,sortOrder, NullPrecedence.fromJpaValue( nullPrecedence ) ); - } - public Expression getSortExpression() { return sortExpression; } @@ -53,12 +49,8 @@ public class SortSpecification implements SqlAstNode { return sortOrder; } - public NullPrecedence getHibernateNullPrecedence() { - return nullPrecedence; - } - public Nulls getNullPrecedence() { - return nullPrecedence.getJpaValue(); + return nullPrecedence; } public boolean isIgnoreCase() { diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-3.2.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-3.2.0.xsd index 1e6ce9c6e9..76cb6f52e7 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-3.2.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-3.2.0.xsd @@ -7,11 +7,11 @@ --> - + version="3.2"> ... ]]> diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java index bcf34e0405..4b3d6e4dea 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java @@ -13,7 +13,7 @@ import org.hibernate.query.sqm.tree.select.SqmSortSpecification; import org.hibernate.testing.TestForIssue; import org.junit.Test; -import static org.hibernate.query.NullPrecedence.FIRST; +import static jakarta.persistence.criteria.Nulls.FIRST; import static org.hibernate.query.SortDirection.ASCENDING; import static org.hibernate.query.SortDirection.DESCENDING; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/resources/xml/jaxb/mapping/partial/hibernate-orm-specific-attributes.xml b/hibernate-core/src/test/resources/xml/jaxb/mapping/partial/hibernate-orm-specific-attributes.xml index 7ec329bc05..287f363a94 100644 --- a/hibernate-core/src/test/resources/xml/jaxb/mapping/partial/hibernate-orm-specific-attributes.xml +++ b/hibernate-core/src/test/resources/xml/jaxb/mapping/partial/hibernate-orm-specific-attributes.xml @@ -6,16 +6,19 @@ ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. ~ See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. --> - + org.hibernate.orm.test.boot.jaxb.mapping - - + + + 1 - + + 2005 +