Skip to content

Upgrade Hibernate ORM to 3.0.0.Beta5 #2160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ org.gradle.java.installations.auto-download=false
#enableMavenLocalRepo = true

# The default Hibernate ORM version (override using `-PhibernateOrmVersion=the.version.you.want`)
hibernateOrmVersion = 7.0.0.Beta4
hibernateOrmVersion = 7.0.0.Beta5

# Override default Hibernate ORM Gradle plugin version
# Using the stable version because I don't know how to configure the build to download the snapshot version from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,8 @@ protected CompletionStage<Void> deleteEntity(
persister
).nullifyTransientReferences( entityEntry.getDeletedState() )
.thenAccept( vv -> {
new Nullability( session ).checkNullability(
entityEntry.getDeletedState(),
persister,
Nullability.NullabilityCheckType.DELETE
);
new Nullability( session, Nullability.NullabilityCheckType.DELETE )
.checkNullability( entityEntry.getDeletedState(), persister );
persistenceContext.registerNullifiableEntityKey( key );

final ReactiveActionQueue actionQueue = actionQueue( session );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.concurrent.CompletionStage;

import org.hibernate.LockOptions;
import org.hibernate.engine.internal.BatchFetchQueueHelper;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
Expand Down Expand Up @@ -160,7 +159,8 @@ private CompletionStage<Void> initializeEntities(
continue;
}
// found or not, remove the key from the batch-fetch queue
BatchFetchQueueHelper.removeBatchLoadableEntityKey( id, getLoadable(), session );
session.getPersistenceContextInternal().getBatchFetchQueue()
.removeBatchLoadableEntityKey( session.generateEntityKey( id, getLoadable().getEntityPersister() ) );
}
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.engine.internal.BatchFetchQueueHelper;
import org.hibernate.engine.spi.BatchFetchQueue;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.EntityKey;
Expand Down Expand Up @@ -206,7 +205,7 @@ protected <K> CompletionStage<List<E>> performOrderedMultiLoad(
// the element value at this position in the result List should be
// the EntityKey for that entity - reuse it
final EntityKey entityKey = (EntityKey) result.get( resultIndex );
BatchFetchQueueHelper.removeBatchLoadableEntityKey( entityKey, session );
session.getPersistenceContextInternal().getBatchFetchQueue().removeBatchLoadableEntityKey( entityKey );
Object entity = persistenceContext.getEntity( entityKey );
if ( entity != null && !loadOptions.isReturnOfDeletedEntitiesEnabled() ) {
// make sure it is not DELETED
Expand Down Expand Up @@ -293,7 +292,8 @@ protected <K> CompletionStage<List<E>> performUnorderedMultiLoad(
continue;
}
// found or not, remove the key from the batch-fetch queue
BatchFetchQueueHelper.removeBatchLoadableEntityKey( id, getLoadable(), session );
session.getPersistenceContextInternal().getBatchFetchQueue()
.removeBatchLoadableEntityKey( session.generateEntityKey( id, getLoadable().getEntityPersister() ) );
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public <R> MutationQuery createQuery(CriteriaDelete<R> criteriaDelete) {

@Override
public <R> Query<R> createNamedQuery(String queryName) {
return new MutinyQueryImpl<>( delegate.createReactiveNamedQuery( queryName, null ), factory );
return new MutinyQueryImpl<>( delegate.createReactiveNamedQuery( queryName ), factory );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Mutiny.MutationQuery createMutationQuery(String queryString) {

@Override
public <R> Query<R> createNamedQuery(String queryName) {
return new MutinyQueryImpl<>( delegate.createReactiveNamedQuery( queryName, null ), factory );
return new MutinyQueryImpl<>( delegate.createReactiveNamedQuery( queryName ), factory );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.hibernate.reactive.query;

import java.io.Serializable;
import java.time.Instant;
import java.util.Calendar;
import java.util.Collection;
Expand All @@ -23,12 +22,6 @@

public interface ReactiveQueryImplementor<R> extends ReactiveQuery<R> {

void setOptionalId(Serializable id);

void setOptionalEntityName(String entityName);

void setOptionalObject(Object optionalObject);

QueryParameterBindings getParameterBindings();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.RootGraph;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.AbstractSharedSessionContract;
import org.hibernate.metamodel.model.domain.BasicDomainType;
import org.hibernate.query.BindableType;
import org.hibernate.query.Order;
Expand Down Expand Up @@ -65,8 +64,18 @@ public class ReactiveNativeQueryImpl<R> extends NativeQueryImpl<R>

private final ReactiveAbstractSelectionQuery<R> selectionQueryDelegate;

public ReactiveNativeQueryImpl(String memento, SharedSessionContractImplementor session) {
super( memento, session );
public ReactiveNativeQueryImpl(String sql, SharedSessionContractImplementor session) {
super( sql, null, session );
this.selectionQueryDelegate = createSelectionQueryDelegate( session );
}

public ReactiveNativeQueryImpl(String sql, Class<R> resultClass, SharedSessionContractImplementor session) {
super( sql, resultClass, session );
this.selectionQueryDelegate = createSelectionQueryDelegate( session );
}

public ReactiveNativeQueryImpl(String sql, NamedResultSetMappingMemento resultSetMappingMemento, Class<R> resultClass, SharedSessionContractImplementor session) {
super( sql, resultSetMappingMemento, resultClass, session);
this.selectionQueryDelegate = createSelectionQueryDelegate( session );
}

Expand All @@ -91,14 +100,6 @@ public ReactiveNativeQueryImpl(
this.selectionQueryDelegate = createSelectionQueryDelegate( session );
}

public ReactiveNativeQueryImpl(
String sqlString,
NamedResultSetMappingMemento resultSetMappingMemento,
AbstractSharedSessionContract session) {
super( sqlString, resultSetMappingMemento, session );
this.selectionQueryDelegate = createSelectionQueryDelegate( session );
}

// Convenient for passing parameters to ReactiveAbstractSelectionQuery using method reference
private <T> T getNull() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.tree.AbstractUpdateOrDeleteStatement;
import org.hibernate.sql.ast.tree.MutationStatement;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.sql.ast.tree.expression.JdbcLiteral;
import org.hibernate.sql.ast.tree.from.MutatingTableReferenceGroupWrapper;
import org.hibernate.sql.ast.tree.from.NamedTableReference;
import org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate;
Expand Down Expand Up @@ -95,29 +93,28 @@ protected SqlAstTranslator<? extends JdbcOperationQueryMutation> createTranslato
return factory.getJdbcServices()
.getJdbcEnvironment()
.getSqlAstTranslatorFactory()
.buildMutationTranslator( factory, mutationStatement() );
.buildMutationTranslator( factory, createDeleteAst() );
}

private MutationStatement mutationStatement() {
// Copy and paste from superclass
private MutationStatement createDeleteAst() {
final MutationStatement ast;
if ( entityDescriptor.getSoftDeleteMapping() == null ) {
return sqmInterpretation.getSqlAst();
ast = sqmInterpretation.getSqlAst();
}
final AbstractUpdateOrDeleteStatement sqlDeleteAst = sqmInterpretation.getSqlAst();
final NamedTableReference targetTable = sqlDeleteAst.getTargetTable();
final SoftDeleteMapping columnMapping = getEntityDescriptor().getSoftDeleteMapping();
final ColumnReference columnReference = new ColumnReference( targetTable, columnMapping );
//noinspection rawtypes,unchecked
final JdbcLiteral jdbcLiteral = new JdbcLiteral(
columnMapping.getDeletedLiteralValue(),
columnMapping.getJdbcMapping()
);
final Assignment assignment = new Assignment( columnReference, jdbcLiteral );

return new UpdateStatement(
targetTable,
Collections.singletonList( assignment ),
sqlDeleteAst.getRestriction()
);
else {
final AbstractUpdateOrDeleteStatement sqlDeleteAst = sqmInterpretation.getSqlAst();
final NamedTableReference targetTable = sqlDeleteAst.getTargetTable();
final SoftDeleteMapping columnMapping = getEntityDescriptor().getSoftDeleteMapping();
final Assignment assignment = columnMapping.createSoftDeleteAssignment( targetTable );

ast = new UpdateStatement(
targetTable,
Collections.singletonList( assignment ),
sqlDeleteAst.getRestriction()
);
}
return ast;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public interface ReactiveQueryProducer extends ReactiveConnectionSupplier {

<R> ReactiveQuery<R> createReactiveQuery(String queryString, Class<R> resultType);

<R> ReactiveQueryImplementor<R> createReactiveNamedQuery(String queryString);

<R> ReactiveQueryImplementor<R> createReactiveNamedQuery(String queryString, Class<R> resultType);

<R> ReactiveNativeQuery<R> createReactiveNativeQuery(String sqlString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.query.IllegalMutationQueryException;
import org.hibernate.query.UnknownNamedQueryException;
import org.hibernate.query.criteria.JpaCriteriaInsert;
import org.hibernate.query.hql.spi.SqmQueryImplementor;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.spi.HqlInterpretation;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
Expand Down Expand Up @@ -131,7 +134,6 @@
import static org.hibernate.engine.spi.NaturalIdResolutions.INVALID_NATURAL_ID_REFERENCE;
import static org.hibernate.event.spi.LoadEventListener.IMMEDIATE_LOAD;
import static org.hibernate.internal.util.StringHelper.isEmpty;
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
import static org.hibernate.reactive.common.InternalStateAssertions.assertUseOnEventLoop;
import static org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister.forceInitialize;
Expand Down Expand Up @@ -443,14 +445,16 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(String sqlString, Cl

@Override @Deprecated(forRemoval = true)
public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(String sqlString, String resultSetMappingName) {
if ( isEmpty( resultSetMappingName ) ) {
throw new IllegalArgumentException( "Result set mapping name was not specified" );
}

checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();

try {
return isNotEmpty( resultSetMappingName )
? new ReactiveNativeQueryImpl<>( sqlString, getResultSetMappingMemento( resultSetMappingName ), this )
: new ReactiveNativeQueryImpl<>( sqlString, this );
return new ReactiveNativeQueryImpl<>( sqlString, getResultSetMappingMemento( resultSetMappingName ), null, this );
//TODO: why no applyQuerySettingsAndHints( query ); ???
}
catch (RuntimeException he) {
Expand Down Expand Up @@ -497,9 +501,78 @@ private <R> ReactiveSelectionQuery<R> createSelectionQuery(String hql, Class<R>
return query;
}

@Override
public <R> ReactiveQueryImplementor<R> createReactiveNamedQuery(String name) {
checksBeforeQueryCreation();
try {
return (ReactiveQueryImplementor<R>) buildNamedQuery(
name,
this::createSqmQueryImplementor,
this::createNativeQueryImplementor
);
}
catch (RuntimeException e) {
throw convertNamedQueryException( e );
}
}

@Override
public <R> ReactiveQueryImplementor<R> createReactiveNamedQuery(String name, Class<R> resultType) {
return (ReactiveQueryImplementor<R>) buildNamedQuery( name, resultType );
checksBeforeQueryCreation();
if ( resultType == null ) {
throw new IllegalArgumentException( "Result class is null" );
}
try {
return buildNamedQuery(
name,
memento -> createReactiveSqmQueryImplementor( resultType, memento ),
memento -> createReactiveNativeQueryImplementor( resultType, memento )
);
}
catch (RuntimeException e) {
throw convertNamedQueryException( e );
}
}

private void checksBeforeQueryCreation() {
checkOpen();
checkTransactionSynchStatus();
}

protected <T> ReactiveNativeQueryImpl<T> createReactiveNativeQueryImplementor(Class<T> resultType, NamedNativeQueryMemento<?> memento) {
final NativeQueryImplementor<T> query = memento.toQuery(this, resultType );
if ( isEmpty( query.getComment() ) ) {
query.setComment( "dynamic native SQL query" );
}
applyQuerySettingsAndHints( query );
return (ReactiveNativeQueryImpl<T>) query;
}

protected <T> ReactiveQuerySqmImpl<T> createReactiveSqmQueryImplementor(Class<T> resultType, NamedSqmQueryMemento<?> memento) {
final SqmQueryImplementor<T> query = memento.toQuery( this, resultType );
if ( isEmpty( query.getComment() ) ) {
query.setComment( "dynamic query" );
}
applyQuerySettingsAndHints( query );
if ( memento.getLockOptions() != null ) {
query.setLockOptions( memento.getLockOptions() );
}
return (ReactiveQuerySqmImpl<T>) query;
}

private RuntimeException convertNamedQueryException(RuntimeException e) {
if ( e instanceof UnknownNamedQueryException ) {
// JPA expects this to mark the transaction for rollback only
getTransactionCoordinator().getTransactionDriverControl().markRollbackOnly();
// it also expects an IllegalArgumentException, so wrap UnknownNamedQueryException
return new IllegalArgumentException( e.getMessage(), e );
}
else if ( e instanceof IllegalArgumentException ) {
return e;
}
else {
return getExceptionConverter().convert( e );
}
}

@Override
Expand Down Expand Up @@ -584,7 +657,7 @@ public <R> ReactiveNativeQuery<R> createReactiveNativeQuery(String queryString,
delayedAfterCompletion();

try {
final ReactiveNativeQueryImpl<R> query = new ReactiveNativeQueryImpl<>( queryString, this );
final ReactiveNativeQueryImpl<R> query = new ReactiveNativeQueryImpl<>( queryString, null, this );
addAffectedEntities( affectedEntities, query );
if ( isEmpty( query.getComment() ) ) {
query.setComment( "dynamic native SQL query" );
Expand Down Expand Up @@ -622,12 +695,11 @@ public <R> ReactiveNativeQueryImpl<R> createReactiveNativeQuery(String queryStri
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();

// Should we throw an exception?
NamedResultSetMappingMemento memento = resultSetMapping == null ? null : getResultSetMappingMemento( resultSetMapping.getName() );
try {
// Same approach as AbstractSharedSessionContract#createNativeQuery(String, String)
final ReactiveNativeQueryImpl<R> nativeQuery = resultSetMapping != null
? new ReactiveNativeQueryImpl<>( queryString, getResultSetMappingMemento( resultSetMapping.getName() ), this )
: new ReactiveNativeQueryImpl<>( queryString, this );
final ReactiveNativeQueryImpl<R> nativeQuery = new ReactiveNativeQueryImpl<>( queryString, memento, null, this );
applyQuerySettingsAndHints( nativeQuery );
return nativeQuery;
}
Expand All @@ -652,20 +724,13 @@ public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String m
if ( mapping == null ) {
throw new IllegalArgumentException( "result set mapping does not exist: " + mappingName );
}
//
// ResultSetMappingImpl resultSetMapping = new ResultSetMappingImpl( "impl" );
// if ( resultType != null ) {
// Class<?> mappedResultType = resultSetMapping.;
// if ( !resultType.equals( mappedResultType ) ) {
// throw new IllegalArgumentException( "incorrect result type for result set mapping: " + mappingName + " has type " + mappedResultType.getName() );
// }
// }

return new ResultSetMapping<>() {
@Override
public String getName() {
return mappingName;
}

@Override
public Class<T> getResultType() {
return resultType;
Expand Down
Loading
Loading