HHH-17377 - Migrate to JPA 3.2

https://hibernate.atlassian.net/browse/HHH-17377

JPA 3.2 B02
This commit is contained in:
Steve Ebersole 2023-11-07 14:49:27 -06:00
parent f8865106c1
commit ad26e73c44
20 changed files with 268 additions and 54 deletions

View File

@ -20,7 +20,7 @@ public class ConfigurationEventReader extends AbstractEventReader {
public ConfigurationEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory) { public ConfigurationEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory) {
super( super(
ROOT_ELEMENT_NAME, ROOT_ELEMENT_NAME,
ConfigXsdSupport.configurationXsd(), ConfigXsdSupport.getJPA32(),
reader, reader,
xmlEventFactory xmlEventFactory
); );

View File

@ -72,6 +72,7 @@ import jakarta.persistence.LockOption;
import jakarta.persistence.RefreshOption; import jakarta.persistence.RefreshOption;
import jakarta.persistence.criteria.CriteriaDelete; import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaSelect;
import jakarta.persistence.criteria.CriteriaUpdate; import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.metamodel.Metamodel; import jakarta.persistence.metamodel.Metamodel;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -507,6 +508,11 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return delegate.getEntityGraph( graphName ); return delegate.getEntityGraph( graphName );
} }
@Override
public <T> QueryImplementor<T> createQuery(CriteriaSelect<T> selectQuery) {
return delegate.createQuery( selectQuery );
}
@Override @Override
public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) { public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) {
return delegate.getEntityGraphs( entityClass ); return delegate.getEntityGraphs( entityClass );

View File

@ -17,11 +17,14 @@ import org.hibernate.event.spi.PersistContext;
import org.hibernate.event.spi.RefreshContext; import org.hibernate.event.spi.RefreshContext;
import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.transaction.spi.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
import jakarta.persistence.criteria.CriteriaSelect;
/** /**
* Defines the "internal contract" between {@link Session} and other parts of Hibernate * Defines the "internal contract" between {@link Session} and other parts of Hibernate
* including implementors of {@link org.hibernate.type.Type}, {@link EntityPersister}, * including implementors of {@link org.hibernate.type.Type}, {@link EntityPersister},
@ -77,6 +80,9 @@ public interface SessionImplementor extends Session, SharedSessionContractImplem
@Override @Override
RootGraphImplementor<?> getEntityGraph(String graphName); RootGraphImplementor<?> getEntityGraph(String graphName);
@Override
<T> QueryImplementor<T> createQuery(CriteriaSelect<T> selectQuery);
/** /**
* Get the {@link ActionQueue} associated with this session. * Get the {@link ActionQueue} associated with this session.
*/ */

View File

@ -53,8 +53,10 @@ import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType; import jakarta.persistence.LockModeType;
import jakarta.persistence.LockOption; import jakarta.persistence.LockOption;
import jakarta.persistence.RefreshOption; import jakarta.persistence.RefreshOption;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaDelete; import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaSelect;
import jakarta.persistence.criteria.CriteriaUpdate; import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.metamodel.Metamodel; import jakarta.persistence.metamodel.Metamodel;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -591,6 +593,11 @@ public class SessionLazyDelegator implements Session {
return this.lazySession.get().createQuery( criteriaQuery ); return this.lazySession.get().createQuery( criteriaQuery );
} }
@Override
public <T> TypedQuery<T> createQuery(CriteriaSelect<T> selectQuery) {
return this.lazySession.get().createQuery( selectQuery );
}
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
@Deprecated @Deprecated

View File

@ -11,6 +11,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import org.hibernate.graph.AttributeNode; import org.hibernate.graph.AttributeNode;
import org.hibernate.graph.CannotBecomeEntityGraphException; import org.hibernate.graph.CannotBecomeEntityGraphException;
@ -95,6 +96,42 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// AttributeNode handling // AttributeNode handling
@Override
public <Y> AttributeNodeImplementor<Y> getAttributeNode(String attributeName) {
if ( attrNodeMap == null ) {
return null;
}
final PersistentAttribute<? super J, ?> attribute = managedType.findAttributeInSuperTypes( attributeName );
//noinspection unchecked
return (AttributeNodeImplementor<Y>) attrNodeMap.get( attribute );
}
@Override
public <Y> AttributeNodeImplementor<Y> getAttributeNode(Attribute<? super J, Y> attribute) {
return null;
}
@Override
public void visitAttributeNodes(Consumer<AttributeNodeImplementor<?>> consumer) {
if ( attrNodeMap == null ) {
return;
}
attrNodeMap.forEach( (persistentAttribute, attributeNodeImplementor) -> {
consumer.accept( attributeNodeImplementor );
} );
}
@Override
public List<AttributeNode<?>> getAttributeNodeList() {
if ( attrNodeMap == null ) {
return emptyList();
}
final List<AttributeNode<?>> result = new ArrayList<>();
visitAttributeNodes( result::add );
return result;
}
@Override @Override
public AttributeNodeImplementor<?> addAttributeNode(AttributeNodeImplementor<?> incomingAttributeNode) { public AttributeNodeImplementor<?> addAttributeNode(AttributeNodeImplementor<?> incomingAttributeNode) {
verifyMutability(); verifyMutability();
@ -151,8 +188,8 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
} }
@Override @Override
public void addAttributeNode(String attributeName) throws CannotContainSubGraphException { public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(String attributeName) throws CannotContainSubGraphException {
findOrCreateAttributeNode( attributeName ); return findOrCreateAttributeNode( attributeName );
} }
@Override @Override
@ -162,8 +199,9 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
} }
@Override @Override
public void addAttributeNode(Attribute<? super J, ?> attribute) { public <Y> AttributeNodeImplementor<Y> addAttributeNode(Attribute<? super J, Y> attribute) {
findOrCreateAttributeNode( (PersistentAttribute<? super J, ?>) attribute ); //noinspection unchecked
return (AttributeNodeImplementor<Y>) findOrCreateAttributeNode( (PersistentAttribute<? super J, ?>) attribute );
} }
@Override @Override

View File

@ -16,6 +16,8 @@ import org.hibernate.graph.Graph;
import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.SqmPathSource;
import jakarta.persistence.metamodel.Attribute;
/** /**
* Integration version of the {@link Graph} contract * Integration version of the {@link Graph} contract
* *
@ -49,6 +51,16 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
getAttributeNodeImplementors().forEach( consumer ); getAttributeNodeImplementors().forEach( consumer );
} }
@Override
default boolean hasAttributeNode(String attributeName) {
return getAttributeNode( attributeName ) != null;
}
@Override
default boolean hasAttributeNode(Attribute<? super J, ?> attribute) {
return getAttributeNode( attribute ) != null;
}
AttributeNodeImplementor<?> addAttributeNode(AttributeNodeImplementor<?> makeCopy); AttributeNodeImplementor<?> addAttributeNode(AttributeNodeImplementor<?> makeCopy);
List<AttributeNodeImplementor<?>> getAttributeNodeImplementors(); List<AttributeNodeImplementor<?>> getAttributeNodeImplementors();
@ -66,7 +78,10 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
<AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? super J, AJ> attribute); <AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? super J, AJ> attribute);
@Override @Override
void addAttributeNode(String attributeName) throws CannotContainSubGraphException; <AJ> AttributeNodeImplementor<AJ> addAttributeNode(String attributeName) throws CannotContainSubGraphException;
@Override
<Y> AttributeNodeImplementor<Y> addAttributeNode(Attribute<? super J, Y> attribute);
@Override @Override
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? super J, AJ> attribute) <AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? super J, AJ> attribute)

View File

@ -856,6 +856,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
return interpretAndCreateSelectionQuery( hqlString, expectedResultType ); return interpretAndCreateSelectionQuery( hqlString, expectedResultType );
} }
@Override @Override
public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) { public <R> SelectionQuery<R> createSelectionQuery(CriteriaQuery<R> criteria) {
if ( criteria instanceof CriteriaDefinition ) { if ( criteria instanceof CriteriaDefinition ) {
@ -1476,7 +1477,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
} }
} }
private <T> QueryImplementor<T> createCriteriaQuery(SqmStatement<T> criteria, Class<T> resultType) { protected <T> QueryImplementor<T> createCriteriaQuery(SqmStatement<T> criteria, Class<T> resultType) {
final QuerySqmImpl<T> query = new QuerySqmImpl<>( criteria, resultType, this ); final QuerySqmImpl<T> query = new QuerySqmImpl<>( criteria, resultType, this );
applyQuerySettingsAndHints( query ); applyQuerySettingsAndHints( query );
return query; return query;

View File

@ -124,6 +124,11 @@ import org.hibernate.proxy.LazyInitializer;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.hibernate.query.SelectionQuery; import org.hibernate.query.SelectionQuery;
import org.hibernate.query.UnknownSqlResultSetMappingException; import org.hibernate.query.UnknownSqlResultSetMappingException;
import org.hibernate.query.criteria.CriteriaDefinition;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.sqm.tree.select.SqmQueryGroup;
import org.hibernate.query.sqm.tree.select.SqmQuerySpec;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector; import org.hibernate.resource.jdbc.spi.StatementInspector;
@ -148,6 +153,7 @@ import jakarta.persistence.LockOption;
import jakarta.persistence.PersistenceException; import jakarta.persistence.PersistenceException;
import jakarta.persistence.RefreshOption; import jakarta.persistence.RefreshOption;
import jakarta.persistence.TransactionRequiredException; import jakarta.persistence.TransactionRequiredException;
import jakarta.persistence.criteria.CriteriaSelect;
import jakarta.persistence.metamodel.Metamodel; import jakarta.persistence.metamodel.Metamodel;
import static java.lang.Boolean.parseBoolean; import static java.lang.Boolean.parseBoolean;
@ -1719,6 +1725,35 @@ public class SessionImpl
return getFactory(); return getFactory();
} }
@Override
public <T> QueryImplementor<T> createQuery(CriteriaSelect<T> selectQuery) {
checkOpen();
if ( selectQuery instanceof CriteriaDefinition ) {
return (QueryImplementor<T>) ((CriteriaDefinition<T>) selectQuery).createSelectionQuery(this);
}
else {
try {
final SqmSelectStatement<T> selectStatement = (SqmSelectStatement<T>) selectQuery;
if ( ! ( selectStatement.getQueryPart() instanceof SqmQueryGroup ) ) {
final SqmQuerySpec<T> querySpec = selectStatement.getQuerySpec();
if ( querySpec.getSelectClause().getSelections().isEmpty() ) {
if ( querySpec.getFromClause().getRoots().size() == 1 ) {
querySpec.getSelectClause().setSelection( querySpec.getFromClause().getRoots().get(0) );
}
}
}
return createCriteriaQuery( selectStatement, selectStatement.getResultType() );
}
catch (RuntimeException e) {
if ( getSessionFactory().getJpaMetamodel().getJpaCompliance().isJpaTransactionComplianceEnabled() ) {
markForRollbackOnly();
}
throw getExceptionConverter().convert( e );
}
}
}
@Override @Override
public void initializeCollection(PersistentCollection<?> collection, boolean writing) { public void initializeCollection(PersistentCollection<?> collection, boolean writing) {
checkOpenOrWaitingForAutoClose(); checkOpenOrWaitingForAutoClose();

View File

@ -166,8 +166,7 @@ public interface QueryProducer {
* *
* @apiNote Changes in JPA 3.2 required de-typing this to be compilable with their changes * @apiNote Changes in JPA 3.2 required de-typing this to be compilable with their changes
*/ */
@SuppressWarnings("rawtypes") <R> NativeQuery<R> createNativeQuery(String sqlString, Class<R> resultClass);
NativeQuery createNativeQuery(String sqlString, Class<?> resultClass);
/** /**
* Create a {@link NativeQuery} instance for the given native SQL query * Create a {@link NativeQuery} instance for the given native SQL query

View File

@ -25,12 +25,14 @@ import org.hibernate.query.NullPrecedence;
import org.hibernate.query.SortDirection; import org.hibernate.query.SortDirection;
import org.hibernate.query.sqm.FrameKind; import org.hibernate.query.sqm.FrameKind;
import org.hibernate.query.sqm.TemporalUnit; import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.AbstractQuery; import jakarta.persistence.criteria.AbstractQuery;
import jakarta.persistence.criteria.CollectionJoin; import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaSelect;
import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.ListJoin;
@ -176,28 +178,34 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder {
<T> JpaCriteriaQuery<T> except(boolean all, CriteriaQuery<? extends T> query1, CriteriaQuery<?>... queries); <T> JpaCriteriaQuery<T> except(boolean all, CriteriaQuery<? extends T> query1, CriteriaQuery<?>... queries);
default <T> JpaSubQuery<T> unionAll(Subquery<? extends T> query1, Subquery<?>... queries) {
return union( true, query1, queries );
}
@Override @Override
<T> CriteriaSelect<T> union(CriteriaSelect<? extends T> left, CriteriaSelect<? extends T> right);
<T> JpaCriteriaQuery<T> union(CriteriaQuery<? extends T> left, CriteriaQuery<? extends T> right); <T> JpaCriteriaQuery<T> union(CriteriaQuery<? extends T> left, CriteriaQuery<? extends T> right);
@Override
default <T> JpaCriteriaQuery<T> unionAll(CriteriaQuery<? extends T> left, CriteriaQuery<? extends T> right) {
return null;
}
default <T> JpaSubQuery<T> union(Subquery<? extends T> query1, Subquery<?>... queries) { default <T> JpaSubQuery<T> union(Subquery<? extends T> query1, Subquery<?>... queries) {
return union( false, query1, queries ); return union( false, query1, queries );
} }
<T> JpaSubQuery<T> union(boolean all, Subquery<? extends T> query1, Subquery<?>... queries); <T> JpaSubQuery<T> union(boolean all, Subquery<? extends T> query1, Subquery<?>... queries);
@Override default <T> JpaSubQuery<T> unionAll(Subquery<? extends T> query1, Subquery<?>... queries) {
<T> JpaCriteriaQuery<T> intersect(CriteriaQuery<? super T> left, CriteriaQuery<? super T> right); return union( true, query1, queries );
}
@Override @Override
<T> CriteriaSelect<T> unionAll(CriteriaSelect<? extends T> left, CriteriaSelect<? extends T> right);
<T> JpaCriteriaQuery<T> unionAll(CriteriaQuery<? extends T> left, CriteriaQuery<? extends T> right);
@Override
<T> CriteriaSelect<T> intersect(CriteriaSelect<? super T> left, CriteriaSelect<? super T> right);
@Override
<T> CriteriaSelect<T> intersectAll(CriteriaSelect<? super T> left, CriteriaSelect<? super T> right);
<T> JpaCriteriaQuery<T> intersect(CriteriaQuery<? super T> left, CriteriaQuery<? super T> right);
<T> JpaCriteriaQuery<T> intersectAll(CriteriaQuery<? super T> left, CriteriaQuery<? super T> right); <T> JpaCriteriaQuery<T> intersectAll(CriteriaQuery<? super T> left, CriteriaQuery<? super T> right);
default <T> JpaSubQuery<T> intersectAll(Subquery<? extends T> query1, Subquery<?>... queries) { default <T> JpaSubQuery<T> intersectAll(Subquery<? extends T> query1, Subquery<?>... queries) {
@ -211,9 +219,13 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder {
<T> JpaSubQuery<T> intersect(boolean all, Subquery<? extends T> query1, Subquery<?>... queries); <T> JpaSubQuery<T> intersect(boolean all, Subquery<? extends T> query1, Subquery<?>... queries);
@Override @Override
<T> JpaCriteriaQuery<T> except(CriteriaQuery<T> left, CriteriaQuery<?> right); <T> CriteriaSelect<T> except(CriteriaSelect<T> left, CriteriaSelect<?> right);
@Override @Override
<T> CriteriaSelect<T> exceptAll(CriteriaSelect<T> left, CriteriaSelect<?> right);
<T> JpaCriteriaQuery<T> except(CriteriaQuery<T> left, CriteriaQuery<?> right);
<T> JpaCriteriaQuery<T> exceptAll(CriteriaQuery<T> left, CriteriaQuery<?> right); <T> JpaCriteriaQuery<T> exceptAll(CriteriaQuery<T> left, CriteriaQuery<?> right);
default <T> JpaSubQuery<T> exceptAll(Subquery<? extends T> query1, Subquery<?>... queries) { default <T> JpaSubQuery<T> exceptAll(Subquery<? extends T> query1, Subquery<?>... queries) {
@ -368,11 +380,11 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder {
@Override @Override
JpaCompoundSelection<Tuple> tuple(Selection<?>... selections); JpaCompoundSelection<Tuple> tuple(Selection<?>... selections);
JpaCompoundSelection<Tuple> tuple(List<? extends JpaSelection<?>> selections); JpaCompoundSelection<Tuple> tuple(List<Selection<?>> selections);
@Override @Override
JpaCompoundSelection<Object[]> array(Selection<?>... selections); JpaCompoundSelection<Object[]> array(Selection<?>... selections);
JpaCompoundSelection<Object[]> array(List<? extends JpaSelection<?>> selections); JpaCompoundSelection<Object[]> array(List<Selection<?>> selections);
<Y> JpaCompoundSelection<Y> array(Class<Y> resultClass, Selection<?>... selections); <Y> JpaCompoundSelection<Y> array(Class<Y> resultClass, Selection<?>... selections);
<Y> JpaCompoundSelection<Y> array(Class<Y> resultClass, List<? extends JpaSelection<?>> selections); <Y> JpaCompoundSelection<Y> array(Class<Y> resultClass, List<? extends JpaSelection<?>> selections);

View File

@ -25,7 +25,7 @@ import jakarta.persistence.metamodel.EntityType;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface JpaCriteriaQuery<T> extends CriteriaQuery<T>, JpaQueryableCriteria<T>, JpaSelectCriteria<T> { public interface JpaCriteriaQuery<T> extends CriteriaQuery<T>, JpaQueryableCriteria<T>, JpaSelectCriteria<T>, JpaCriteriaSelect<T> {
/** /**
* A query that returns the number of results of this query. * A query that returns the number of results of this query.

View File

@ -0,0 +1,23 @@
/*
* 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.criteria;
import jakarta.persistence.criteria.CriteriaSelect;
/**
* Extension of the JPA {@link CriteriaSelect}.
*
* @apiNote This is different from {@link JpaSelectCriteria}. JPA added
* {@link CriteriaSelect} in version 3.2 while {@link JpaSelectCriteria} has
* existed for many releases prior. JPA's {@link CriteriaSelect} is intended
* for supporting its newly added set operations (union, interest, except).
*
* @author Steve Ebersole
*/
public interface JpaCriteriaSelect<T> extends CriteriaSelect<T> {
}

View File

@ -25,7 +25,7 @@ import org.hibernate.query.sqm.FetchClauseType;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface JpaSubQuery<T> extends Subquery<T>, JpaSelectCriteria<T>, JpaExpression<T>, JpaCteContainer { public interface JpaSubQuery<T> extends Subquery<T>, JpaSelectCriteria<T>, JpaCriteriaSelect<T>, JpaExpression<T>, JpaCteContainer {
JpaSubQuery<T> multiselect(Selection<?>... selections); JpaSubQuery<T> multiselect(Selection<?>... selections);

View File

@ -62,6 +62,7 @@ import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CollectionJoin; import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaSelect;
import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.ListJoin;
@ -211,11 +212,21 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
return criteriaBuilder.except( all, query1, queries ); return criteriaBuilder.except( all, query1, queries );
} }
@Override
public <T> CriteriaSelect<T> union(CriteriaSelect<? extends T> left, CriteriaSelect<? extends T> right) {
return criteriaBuilder.union( left, right );
}
@Override @Override
public <T> JpaSubQuery<T> unionAll(Subquery<? extends T> query1, Subquery<?>... queries) { public <T> JpaSubQuery<T> unionAll(Subquery<? extends T> query1, Subquery<?>... queries) {
return criteriaBuilder.unionAll( query1, queries ); return criteriaBuilder.unionAll( query1, queries );
} }
@Override
public <T> CriteriaSelect<T> unionAll(CriteriaSelect<? extends T> left, CriteriaSelect<? extends T> right) {
return criteriaBuilder.unionAll( left, right );
}
@Override @Override
public <T> JpaSubQuery<T> union(Subquery<? extends T> query1, Subquery<?>... queries) { public <T> JpaSubQuery<T> union(Subquery<? extends T> query1, Subquery<?>... queries) {
return criteriaBuilder.union( query1, queries ); return criteriaBuilder.union( query1, queries );
@ -241,6 +252,16 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
return criteriaBuilder.intersect( all, query1, queries ); return criteriaBuilder.intersect( all, query1, queries );
} }
@Override
public <T> CriteriaSelect<T> except(CriteriaSelect<T> left, CriteriaSelect<?> right) {
return criteriaBuilder.except( left, right );
}
@Override
public <T> CriteriaSelect<T> exceptAll(CriteriaSelect<T> left, CriteriaSelect<?> right) {
return criteriaBuilder.exceptAll( left, right );
}
@Override @Override
public <T> JpaSubQuery<T> exceptAll(Subquery<? extends T> query1, Subquery<?>... queries) { public <T> JpaSubQuery<T> exceptAll(Subquery<? extends T> query1, Subquery<?>... queries) {
return criteriaBuilder.exceptAll( query1, queries ); return criteriaBuilder.exceptAll( query1, queries );
@ -348,6 +369,16 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
return criteriaBuilder.unionAll( left, right ); return criteriaBuilder.unionAll( left, right );
} }
@Override
public <T> CriteriaSelect<T> intersect(CriteriaSelect<? super T> left, CriteriaSelect<? super T> right) {
return criteriaBuilder.intersect( left, right );
}
@Override
public <T> CriteriaSelect<T> intersectAll(CriteriaSelect<? super T> left, CriteriaSelect<? super T> right) {
return criteriaBuilder.intersectAll( left, right );
}
@Override @Override
public <T> JpaCriteriaQuery<T> intersect(CriteriaQuery<? super T> left, CriteriaQuery<? super T> right) { public <T> JpaCriteriaQuery<T> intersect(CriteriaQuery<? super T> left, CriteriaQuery<? super T> right) {
return criteriaBuilder.intersect( left, right ); return criteriaBuilder.intersect( left, right );
@ -409,7 +440,7 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
} }
@Override @Override
public JpaCompoundSelection<Tuple> tuple(List<? extends JpaSelection<?>> selections) { public JpaCompoundSelection<Tuple> tuple(List<Selection<?>> selections) {
return criteriaBuilder.tuple( selections ); return criteriaBuilder.tuple( selections );
} }
@ -419,7 +450,7 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde
} }
@Override @Override
public JpaCompoundSelection<Object[]> array(List<? extends JpaSelection<?>> selections) { public JpaCompoundSelection<Object[]> array(List<Selection<?>> selections) {
return criteriaBuilder.array( selections ); return criteriaBuilder.array( selections );
} }

View File

@ -47,9 +47,8 @@ public interface QueryProducerImplementor extends QueryProducer {
@Override @Deprecated @SuppressWarnings("rawtypes") @Override @Deprecated @SuppressWarnings("rawtypes")
NativeQueryImplementor createNativeQuery(String sqlString); NativeQueryImplementor createNativeQuery(String sqlString);
@SuppressWarnings("rawtypes")
@Override @Override
NativeQueryImplementor createNativeQuery(String sqlString, Class<?> resultClass); <R> NativeQueryImplementor<R> createNativeQuery(String sqlString, Class<R> resultClass);
@Override @Override
<R> NativeQueryImplementor<R> createNativeQuery(String sqlString, Class<R> resultClass, String tableAlias); <R> NativeQueryImplementor<R> createNativeQuery(String sqlString, Class<R> resultClass, String tableAlias);

View File

@ -64,7 +64,6 @@ import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.MapJoin; import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Nulls;
import jakarta.persistence.criteria.Path; import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Root;
@ -636,13 +635,13 @@ public interface NodeBuilder extends HibernateCriteriaBuilder {
JpaCompoundSelection<Tuple> tuple(Selection<?>[] selections); JpaCompoundSelection<Tuple> tuple(Selection<?>[] selections);
@Override @Override
JpaCompoundSelection<Tuple> tuple(List<? extends JpaSelection<?>> selections); JpaCompoundSelection<Tuple> tuple(List<Selection<?>> selections);
@Override @Override
JpaCompoundSelection<Object[]> array(Selection<?>[] selections); JpaCompoundSelection<Object[]> array(Selection<?>[] selections);
@Override @Override
JpaCompoundSelection<Object[]> array(List<? extends JpaSelection<?>> selections); JpaCompoundSelection<Object[]> array(List<Selection<?>> selections);
@Override @Override
<T> SqmUpdateStatement<T> createCriteriaUpdate(Class<T> targetEntity); <T> SqmUpdateStatement<T> createCriteriaUpdate(Class<T> targetEntity);

View File

@ -58,6 +58,7 @@ import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCoalesce; import org.hibernate.query.criteria.JpaCoalesce;
import org.hibernate.query.criteria.JpaCompoundSelection; import org.hibernate.query.criteria.JpaCompoundSelection;
import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.query.criteria.JpaCriteriaSelect;
import org.hibernate.query.criteria.JpaCteCriteriaAttribute; import org.hibernate.query.criteria.JpaCteCriteriaAttribute;
import org.hibernate.query.criteria.JpaExpression; import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaFunction; import org.hibernate.query.criteria.JpaFunction;
@ -170,6 +171,7 @@ import org.hibernate.type.spi.TypeConfiguration;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CollectionJoin; import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaSelect;
import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.ListJoin;
@ -406,16 +408,42 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
return setOperation( all ? SetOperator.EXCEPT_ALL : SetOperator.EXCEPT, query1, queries ); return setOperation( all ? SetOperator.EXCEPT_ALL : SetOperator.EXCEPT, query1, queries );
} }
@Override
public <T> JpaCriteriaSelect<T> union(CriteriaSelect<? extends T> left, CriteriaSelect<? extends T> right) {
if ( left instanceof Subquery<?> ) {
assert right instanceof Subquery<?>;
//noinspection unchecked
return setOperation( SetOperator.UNION, (Subquery<T>) left, (Subquery<T>) right );
}
//noinspection unchecked
return setOperation( SetOperator.UNION, (JpaCriteriaQuery<T>) left, (JpaCriteriaQuery<T>) right );
}
@Override @Override
public <T> JpaSubQuery<T> union(boolean all, Subquery<? extends T> query1, Subquery<?>... queries) { public <T> JpaSubQuery<T> union(boolean all, Subquery<? extends T> query1, Subquery<?>... queries) {
return setOperation( all ? SetOperator.UNION_ALL : SetOperator.UNION, query1, queries ); return setOperation( all ? SetOperator.UNION_ALL : SetOperator.UNION, query1, queries );
} }
@Override
public <T> CriteriaSelect<T> unionAll(CriteriaSelect<? extends T> left, CriteriaSelect<? extends T> right) {
return null;
}
@Override @Override
public <T> JpaSubQuery<T> intersect(boolean all, Subquery<? extends T> query1, Subquery<?>... queries) { public <T> JpaSubQuery<T> intersect(boolean all, Subquery<? extends T> query1, Subquery<?>... queries) {
return setOperation( all ? SetOperator.INTERSECT_ALL : SetOperator.INTERSECT, query1, queries ); return setOperation( all ? SetOperator.INTERSECT_ALL : SetOperator.INTERSECT, query1, queries );
} }
@Override
public <T> CriteriaSelect<T> except(CriteriaSelect<T> left, CriteriaSelect<?> right) {
return null;
}
@Override
public <T> CriteriaSelect<T> exceptAll(CriteriaSelect<T> left, CriteriaSelect<?> right) {
return null;
}
@Override @Override
public <T> JpaSubQuery<T> except(boolean all, Subquery<? extends T> query1, Subquery<?>... queries) { public <T> JpaSubQuery<T> except(boolean all, Subquery<? extends T> query1, Subquery<?>... queries) {
return setOperation( all ? SetOperator.EXCEPT_ALL : SetOperator.EXCEPT, query1, queries ); return setOperation( all ? SetOperator.EXCEPT_ALL : SetOperator.EXCEPT, query1, queries );
@ -557,6 +585,16 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
return createUnionSet( SetOperator.UNION_ALL, left, right ); return createUnionSet( SetOperator.UNION_ALL, left, right );
} }
@Override
public <T> CriteriaSelect<T> intersect(CriteriaSelect<? super T> left, CriteriaSelect<? super T> right) {
return null;
}
@Override
public <T> CriteriaSelect<T> intersectAll(CriteriaSelect<? super T> left, CriteriaSelect<? super T> right) {
return null;
}
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
private static <T> JpaCriteriaQuery<T> createUnionSet( private static <T> JpaCriteriaQuery<T> createUnionSet(
SetOperator operator, SetOperator operator,
@ -786,13 +824,18 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
@Override @Override
public JpaCompoundSelection<Tuple> tuple(Selection<?>[] selections) { public JpaCompoundSelection<Tuple> tuple(Selection<?>[] selections) {
//noinspection unchecked return tuple( Arrays.asList( selections ) );
return tuple( (List<SqmSelectableNode<?>>) (List<?>) Arrays.asList( selections ) );
} }
@Override @Override
public JpaCompoundSelection<Tuple> tuple(List<? extends JpaSelection<?>> selections) { public JpaCompoundSelection<Tuple> tuple(List<Selection<?>> selections) {
return null; checkMultiselect( selections );
//noinspection unchecked,rawtypes
return new SqmJpaCompoundSelection<>(
(List) selections,
getTypeConfiguration().getJavaTypeRegistry().getDescriptor( Tuple.class ),
this
);
} }
@Override @Override
@ -825,13 +868,13 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
@Override @Override
public JpaCompoundSelection<Object[]> array(Selection<?>[] selections) { public JpaCompoundSelection<Object[]> array(Selection<?>[] selections) {
//noinspection unchecked return array( Arrays.asList( selections ) );
return array( (List<SqmSelectableNode<?>>) (List<?>) Arrays.asList( selections ) );
} }
@Override @Override
public JpaCompoundSelection<Object[]> array(List<? extends JpaSelection<?>> selections) { public JpaCompoundSelection<Object[]> array(List<Selection<?>> selections) {
return array( Object[].class, selections ); //noinspection unchecked,rawtypes
return array( Object[].class, (List) selections );
} }
@Override @Override
@ -842,7 +885,8 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
@Override @Override
public <Y> JpaCompoundSelection<Y> array(Class<Y> resultClass, List<? extends JpaSelection<?>> selections) { public <Y> JpaCompoundSelection<Y> array(Class<Y> resultClass, List<? extends JpaSelection<?>> selections) {
checkMultiselect( selections ); //noinspection rawtypes,unchecked
checkMultiselect( (List) selections );
final JavaType<Y> javaType = getTypeConfiguration().getJavaTypeRegistry().getDescriptor( resultClass ); final JavaType<Y> javaType = getTypeConfiguration().getJavaTypeRegistry().getDescriptor( resultClass );
//noinspection unchecked //noinspection unchecked
return new SqmJpaCompoundSelection<>( (List<SqmSelectableNode<?>>) selections, javaType, this ); return new SqmJpaCompoundSelection<>( (List<SqmSelectableNode<?>>) selections, javaType, this );
@ -856,7 +900,8 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
@Override @Override
public <Y> JpaCompoundSelection<Y> construct(Class<Y> resultClass, List<? extends JpaSelection<?>> arguments) { public <Y> JpaCompoundSelection<Y> construct(Class<Y> resultClass, List<? extends JpaSelection<?>> arguments) {
checkMultiselect( arguments ); //noinspection unchecked,rawtypes
checkMultiselect( (List) arguments );
final SqmDynamicInstantiation<Y> instantiation; final SqmDynamicInstantiation<Y> instantiation;
if ( List.class.equals( resultClass ) ) { if ( List.class.equals( resultClass ) ) {
//noinspection unchecked //noinspection unchecked
@ -891,10 +936,11 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
* <i>&quot;An argument to the multiselect method must not be a tuple- * <i>&quot;An argument to the multiselect method must not be a tuple-
* or array-valued compound selection item.&quot;</i> * or array-valued compound selection item.&quot;</i>
*/ */
void checkMultiselect(List<? extends JpaSelection<?>> selections) { void checkMultiselect(List<Selection<?>> selections) {
final HashSet<String> aliases = new HashSet<>( CollectionHelper.determineProperSizing( selections.size() ) ); final HashSet<String> aliases = new HashSet<>( CollectionHelper.determineProperSizing( selections.size() ) );
for ( JpaSelection<?> selection : selections ) { for ( Selection<?> it : selections ) {
final JpaSelection<?> selection = (JpaSelection<?>) it;
if ( selection.isCompoundSelection() ) { if ( selection.isCompoundSelection() ) {
if ( selection.getJavaType().isArray() ) { if ( selection.getJavaType().isArray() ) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

View File

@ -31,7 +31,6 @@ import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.from.SqmRoot;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Order; import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.ParameterExpression; import jakarta.persistence.criteria.ParameterExpression;
@ -331,8 +330,8 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Selection<? extends T> getResultSelection(List<?> selectionList) { private Selection<? extends T> getResultSelection(List<?> selectionList) {
final Class<T> resultType = getResultType(); final Class<T> resultType = getResultType();
final List<? extends JpaSelection<?>> selections = //noinspection rawtypes
(List<? extends JpaSelection<?>>) selectionList; final List<? extends JpaSelection<?>> selections = (List) selectionList;
if ( resultType == null || resultType == Object.class ) { if ( resultType == null || resultType == Object.class ) {
switch ( selectionList.size() ) { switch ( selectionList.size() ) {
case 0: { case 0: {
@ -344,12 +343,12 @@ public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements
return (Selection<? extends T>) selectionList.get( 0 ); return (Selection<? extends T>) selectionList.get( 0 );
} }
default: { default: {
return (Selection<? extends T>) nodeBuilder().array( selections ); return (Selection<? extends T>) nodeBuilder().array( selectionList );
} }
} }
} }
else if ( Tuple.class.isAssignableFrom( resultType ) ) { else if ( Tuple.class.isAssignableFrom( resultType ) ) {
return (Selection<? extends T>) nodeBuilder().tuple( selections ); return (Selection<? extends T>) nodeBuilder().tuple( selectionList );
} }
else if ( resultType.isArray() ) { else if ( resultType.isArray() ) {
return nodeBuilder().array( resultType, selections ); return nodeBuilder().array( resultType, selections );

View File

@ -41,7 +41,6 @@ import org.hibernate.query.sqm.tree.domain.SqmCorrelatedListJoin;
import org.hibernate.query.sqm.tree.domain.SqmCorrelatedMapJoin; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedMapJoin;
import org.hibernate.query.sqm.tree.domain.SqmCorrelatedRoot; import org.hibernate.query.sqm.tree.domain.SqmCorrelatedRoot;
import org.hibernate.query.sqm.tree.domain.SqmCorrelatedSetJoin; 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.SqmCorrelatedSingularValuedJoin;
import org.hibernate.query.sqm.tree.domain.SqmCorrelation; import org.hibernate.query.sqm.tree.domain.SqmCorrelation;
import org.hibernate.query.sqm.tree.domain.SqmListJoin; import org.hibernate.query.sqm.tree.domain.SqmListJoin;
@ -49,7 +48,6 @@ import org.hibernate.query.sqm.tree.domain.SqmMapJoin;
import org.hibernate.query.sqm.tree.domain.SqmSetJoin; import org.hibernate.query.sqm.tree.domain.SqmSetJoin;
import org.hibernate.query.sqm.tree.domain.SqmSingularValuedJoin; import org.hibernate.query.sqm.tree.domain.SqmSingularValuedJoin;
import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.query.sqm.tree.from.SqmAttributeJoin;
import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin;
import org.hibernate.query.sqm.tree.from.SqmEntityJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin;
import org.hibernate.query.sqm.tree.from.SqmFromClause; import org.hibernate.query.sqm.tree.from.SqmFromClause;
@ -276,12 +274,12 @@ public class SqmSubQuery<T> extends AbstractSqmSelectQuery<T> implements SqmSele
break; break;
} }
default: { default: {
resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selections ); resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selectionList );
} }
} }
} }
else if ( Tuple.class.isAssignableFrom( resultType ) ) { else if ( Tuple.class.isAssignableFrom( resultType ) ) {
resultSelection = ( Selection<? extends T> ) nodeBuilder().tuple( selections ); resultSelection = ( Selection<? extends T> ) nodeBuilder().tuple( selectionList );
} }
else if ( resultType.isArray() ) { else if ( resultType.isArray() ) {
resultSelection = nodeBuilder().array( resultType, selections ); resultSelection = nodeBuilder().array( resultType, selections );

View File

@ -18,7 +18,7 @@ import org.gradle.api.initialization.Settings;
public class JpaVersion { public class JpaVersion {
public static final String EXT_KEY = "jakartaJpaVersion"; public static final String EXT_KEY = "jakartaJpaVersion";
public static final String VERSION_KEY = "jakartaJpaVersionOverride"; public static final String VERSION_KEY = "jakartaJpaVersionOverride";
public static final String DEFAULT_VERSION = "3.2.0-B01"; public static final String DEFAULT_VERSION = "3.2.0-B02";
private final String name; private final String name;
private final String osgiName; private final String osgiName;