Skip to content

Commit

Permalink
[#1895] Upgrade Hibernate ORM to 7.0.0.Beta3
Browse files Browse the repository at this point in the history
Notes:

* The Hibernate Gradle plugin has not been released yet, so we keep it to 7.0.0.Beta2
* XML sql data type is not supported: eclipse-vertx/vertx-sql-client#1475
* Stop using `org.hibernate.dialect.DialectDelegateWrapper` (not
  required anymore)
* Remove `ReactiveOracleSqlAstTranslator` (not required anymore)
* Only process parameters for native queries. See #2012
* Remove `ReactiveIdentifierGeneratorFactory`: the service doesn't exist
  anymore in ORM
* Add `persist(String, Object)` to the session
* Remove test for `hibernate.create_empty_composites.enabled`: see [HHH-18222](https://hibernate.atlassian.net/browse/HHH-18222)
* Contains some clean ups
* There are still some issues with embeddable mapped as JSON and native queries: See #1999
  • Loading branch information
DavideD committed Dec 12, 2024
1 parent 78b1348 commit 8f9680c
Show file tree
Hide file tree
Showing 129 changed files with 2,604 additions and 2,436 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ org.gradle.java.installations.auto-download=false
#enableMavenLocalRepo = true

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

# 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
# a remote repository
#hibernateOrmGradlePluginVersion = 6.6.3.Final
hibernateOrmGradlePluginVersion = 7.0.0.Beta2

# If set to true, skip Hibernate ORM version parsing (default is true, if set to null)
# this is required when using intervals or weird versions or the build will fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
*/
package org.hibernate.reactive.adaptor.impl;

import io.vertx.core.buffer.Buffer;

import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -39,12 +34,23 @@
import java.util.Calendar;
import java.util.function.Function;

import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.reactive.logging.impl.Log;

import io.vertx.core.buffer.Buffer;

import static java.lang.invoke.MethodHandles.lookup;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;

/**
* Collects parameter bindings from Hibernate core code
* that expects a JDBC {@link PreparedStatement}.
*/
public class PreparedStatementAdaptor implements PreparedStatement {

private static final Log LOG = make( Log.class, lookup() );

@FunctionalInterface
public interface Binder {
void bind(PreparedStatement statement) throws SQLException;
Expand Down Expand Up @@ -315,7 +321,7 @@ public void setNClob(int parameterIndex, Reader reader, long length) {

@Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) {
throw new UnsupportedOperationException();
throw LOG.unsupportedXmlType();
}

@Override
Expand Down Expand Up @@ -540,7 +546,7 @@ public int[] executeBatch() {

@Override
public Connection getConnection() {
throw new UnsupportedOperationException();
throw LOG.unexpectedConnectionRequest();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
import java.util.NoSuchElementException;
import java.util.function.Function;

import org.hibernate.engine.jdbc.BlobProxy;
import org.hibernate.engine.jdbc.ClobProxy;
import org.hibernate.engine.jdbc.proxy.BlobProxy;
import org.hibernate.engine.jdbc.proxy.ClobProxy;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.type.descriptor.jdbc.JdbcType;

import io.vertx.core.buffer.Buffer;
Expand All @@ -48,15 +49,19 @@
import io.vertx.sqlclient.desc.ColumnDescriptor;
import io.vertx.sqlclient.impl.RowBase;

import static java.lang.invoke.MethodHandles.lookup;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;

/**
* An adaptor that allows Hibernate core code which expects a JDBC
* {@code ResultSet} to read values from Vert.x's {@code RowSet}.
*/
public class ResultSetAdaptor implements ResultSet {

private static final Log LOG = make( Log.class, lookup() );

private final Iterator<? extends Row> iterator;

private final List<ColumnDescriptor> columnDescriptors;
Expand Down Expand Up @@ -866,12 +871,12 @@ public NClob getNClob(String columnLabel) {

@Override
public SQLXML getSQLXML(int columnIndex) {
throw new UnsupportedOperationException();
throw LOG.unsupportedXmlType();
}

@Override
public SQLXML getSQLXML(String columnLabel) {
throw new UnsupportedOperationException();
throw LOG.unsupportedXmlType();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.hibernate.boot.spi.AbstractDelegatingMetadata;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.reactive.query.internal.ReactiveNamedObjectRepositoryImpl;

Expand All @@ -18,7 +17,7 @@ public ReactiveMetadataImplementor(MetadataImplementor delegate) {
}

@Override
public NamedObjectRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
return new ReactiveNamedObjectRepositoryImpl( delegate().buildNamedQueryRepository( sessionFactory ) );
public NamedObjectRepository buildNamedQueryRepository() {
return new ReactiveNamedObjectRepositoryImpl( super.buildNamedQueryRepository() );
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.PropertyValueException;
import org.hibernate.TransientObjectException;
import org.hibernate.action.internal.AbstractEntityInsertAction;
import org.hibernate.action.internal.BulkOperationCleanupAction;
import org.hibernate.action.internal.EntityDeleteAction;
import org.hibernate.action.internal.UnresolvedEntityInsertActions;
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
import org.hibernate.action.spi.Executable;
import org.hibernate.cache.CacheException;
import org.hibernate.engine.internal.NonNullableTransientDependencies;
import org.hibernate.engine.spi.ActionQueue;
import org.hibernate.engine.spi.ComparableExecutable;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.engine.spi.ExecutableList;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
Expand All @@ -59,7 +61,6 @@

import static java.lang.invoke.MethodHandles.lookup;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture;
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;

Expand Down Expand Up @@ -520,11 +521,21 @@ public CompletionStage<Void> executeInserts() {
*/
public CompletionStage<Void> executeActions() {
if ( hasUnresolvedEntityInsertActions() ) {
return failedFuture( new IllegalStateException( "About to execute actions, but there are unresolved entity insert actions." ) );
final AbstractEntityInsertAction insertAction = unresolvedInsertions
.getDependentEntityInsertActions()
.iterator()
.next();
final NonNullableTransientDependencies transientEntities = insertAction.findNonNullableTransientEntities();
final Object transientEntity = transientEntities.getNonNullableTransientEntities().iterator().next();
final String path = transientEntities.getNonNullableTransientPropertyPaths(transientEntity).iterator().next();
//TODO: should be TransientPropertyValueException
throw new TransientObjectException( "Persistent instance of '" + insertAction.getEntityName()
+ "' with id '" + insertAction.getId()
+ "' references an unsaved transient instance via attribute '" + path
+ "' (save the transient instance before flushing)" );
}

CompletionStage<Void> ret = voidFuture();

for ( OrderedActions action : ORDERED_OPERATIONS ) {
ret = ret.thenCompose( v -> executeActions( action.getActions( this ) ) );
}
Expand Down Expand Up @@ -738,26 +749,6 @@ public int numberOfInsertions() {
return insertions.size();
}

// public TransactionCompletionProcesses getTransactionCompletionProcesses() {
// return new TransactionCompletionProcesses( beforeTransactionProcesses(), afterTransactionProcesses() );
// }
//
// /**
// * Bind transaction completion processes to make them shared between primary and secondary session.
// * Transaction completion processes are always executed by transaction owner (primary session),
// * but can be registered using secondary session too.
// *
// * @param processes Transaction completion processes.
// * @param isTransactionCoordinatorShared Flag indicating shared transaction context.
// */
// public void setTransactionCompletionProcesses(
// TransactionCompletionProcesses processes,
// boolean isTransactionCoordinatorShared) {
// this.isTransactionCoordinatorShared = isTransactionCoordinatorShared;
// this.beforeTransactionProcesses = processes.beforeTransactionCompletionProcesses;
// this.afterTransactionProcesses = processes.afterTransactionCompletionProcesses;
// }

public void sortCollectionActions() {
if ( isOrderUpdatesEnabled() ) {
// sort the updates by fk
Expand Down Expand Up @@ -864,32 +855,6 @@ public void unScheduleDeletion(EntityEntry entry, Object rescuedEntity) {
throw new AssertionFailure( "Unable to perform un-delete for instance " + entry.getEntityName() );
}

// /**
// * Used by the owning session to explicitly control serialization of the action queue
// *
// * @param oos The stream to which the action queue should get written
// *
// * @throws IOException Indicates an error writing to the stream
// */
// public void serialize(ObjectOutputStream oos) throws IOException {
// LOG.trace( "Serializing action-queue" );
// if ( unresolvedInsertions == null ) {
// unresolvedInsertions = new UnresolvedEntityInsertActions();
// }
// unresolvedInsertions.serialize( oos );
//
// for ( ListProvider<?> p : EXECUTABLE_LISTS_MAP.values() ) {
// ExecutableList<?> l = p.get( this );
// if ( l == null ) {
// oos.writeBoolean( false );
// }
// else {
// oos.writeBoolean( true );
// l.writeExternal( oos );
// }
// }
// }

private abstract static class AbstractTransactionCompletionProcessQueue<T,U> {
final ReactiveSession session;

Expand Down Expand Up @@ -994,21 +959,6 @@ public CompletionStage<Void> afterTransactionCompletion(boolean success) {
}
}

// /**
// * Wrapper class allowing to bind the same transaction completion process queues in different sessions.
// */
// public static class TransactionCompletionProcesses {
// private final BeforeTransactionCompletionProcessQueue beforeTransactionCompletionProcesses;
// private final AfterTransactionCompletionProcessQueue afterTransactionCompletionProcesses;
//
// private TransactionCompletionProcesses(
// BeforeTransactionCompletionProcessQueue beforeTransactionCompletionProcessQueue,
// AfterTransactionCompletionProcessQueue afterTransactionCompletionProcessQueue) {
// this.beforeTransactionCompletionProcesses = beforeTransactionCompletionProcessQueue;
// this.afterTransactionCompletionProcesses = afterTransactionCompletionProcessQueue;
// }
// }

/**
* Order the {@link #insertions} queue such that we group inserts against the same entity together (without
* violating constraints). The original order is generated by cascade order, which in turn is based on the
Expand Down Expand Up @@ -1152,26 +1102,23 @@ public void sort(List<ReactiveEntityInsertActionHolder> insertions) {
*/
private void addParentChildEntityNames(ReactiveEntityInsertAction action, BatchIdentifier batchIdentifier) {
Object[] propertyValues = action.getState();
ClassMetadata classMetadata = action.getPersister().getClassMetadata();
if ( classMetadata != null ) {
Type[] propertyTypes = classMetadata.getPropertyTypes();
Type identifierType = classMetadata.getIdentifierType();

for ( int i = 0; i < propertyValues.length; i++ ) {
Object value = propertyValues[i];
if (value!=null) {
Type type = propertyTypes[i];
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, value );
}
Type[] propertyTypes = action.getPersister().getPropertyTypes();
Type identifierType = action.getPersister().getIdentifierType();

for ( int i = 0; i < propertyValues.length; i++ ) {
Object value = propertyValues[i];
if (value!=null) {
Type type = propertyTypes[i];
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, value );
}
}

if ( identifierType.isComponentType() ) {
CompositeType compositeType = (CompositeType) identifierType;
Type[] compositeIdentifierTypes = compositeType.getSubtypes();
if ( identifierType.isComponentType() ) {
CompositeType compositeType = (CompositeType) identifierType;
Type[] compositeIdentifierTypes = compositeType.getSubtypes();

for ( Type type : compositeIdentifierTypes ) {
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, null );
}
for ( Type type : compositeIdentifierTypes ) {
addParentChildEntityNameByPropertyAndValue( action, batchIdentifier, type, null );
}
}
}
Expand Down Expand Up @@ -1275,10 +1222,9 @@ public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof BatchIdentifier ) ) {
if ( !( o instanceof BatchIdentifier that ) ) {
return false;
}
BatchIdentifier that = (BatchIdentifier) o;
return Objects.equals( entityName, that.entityName );
}

Expand Down Expand Up @@ -1315,9 +1261,7 @@ boolean hasAnyChildEntityNames(BatchIdentifier batchIdentifier) {
/**
* Check if this {@link BatchIdentifier} has a parent or grandparent
* matching the given {@link BatchIdentifier reference.
*
* @param batchIdentifier {@link BatchIdentifier} reference
*
* @return this {@link BatchIdentifier} has a parent matching the given {@link BatchIdentifier reference
*/
boolean hasParent(BatchIdentifier batchIdentifier) {
Expand Down
Loading

0 comments on commit 8f9680c

Please sign in to comment.