Skip to content

Commit

Permalink
[#1927] Fix support for Hibernate ORM 6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Oct 26, 2024
1 parent 634799c commit c2b6c31
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ jobs:
shell: bash

- name: Upload test reports (if Maven failed)
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-reports-${{ matrix.provider }}-${{ matrix.rdbms }}-jdk${{ matrix.jdk }}-build-jdk${{ matrix.build-jdk }}-${{ matrix.deltaspike }}-${{ matrix.spring-data }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
shell: bash

- name: Upload test reports (if Maven failed)
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-reports-${{ matrix.component }}
Expand Down
2 changes: 1 addition & 1 deletion core/testsuite-hibernate6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
<profile>
<id>hibernate-6.6</id>
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion core/testsuite-jakarta-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
<id>hibernate-6.6</id>
<properties>
<jpa-api-version>${version.jakarta-jpa-3.1-api}</jpa-api-version>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion core/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@
<id>hibernate-6.6</id>
<!-- Note that we compile the test suite against Hibernate 5.6 because this testsuite will be jakarta-transformed -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
<additional.source.directory>src/main/hibernate</additional.source.directory>
</properties>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion entity-view/testsuite-jakarta-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@
<id>hibernate-6.6</id>
<properties>
<jpa-api-version>${version.jakarta-jpa-3.1-api}</jpa-api-version>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion entity-view/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@
<id>hibernate-6.6</id>
<!-- Note that we compile the test suite against Hibernate 5.6 because this testsuite will be jakarta-transformed -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.blazebit.persistence.view.testsuite.collections.singleton;

import com.blazebit.persistence.CriteriaBuilder;
import com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66;
import com.blazebit.persistence.testsuite.tx.TxVoidWork;
import com.blazebit.persistence.view.EntityViewManager;
import com.blazebit.persistence.view.EntityViewSetting;
Expand All @@ -29,6 +30,7 @@
import com.blazebit.persistence.testsuite.entity.Person;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import javax.persistence.EntityManager;
import java.util.List;
Expand Down Expand Up @@ -88,7 +90,9 @@ public void setUp() {
doc4 = cbf.create(em, Document.class).where("name").eq("doc4").getSingleResult();
}

// NOTE: Hibernate ORM 6.6.1 has a bug: https://hibernate.atlassian.net/browse/HHH-18773
@Test
@Category(NoHibernate66.class)
public void testSingletonCollections() {
EntityViewManager evm = build(
SingletonDocumentCollectionsView.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.blazebit.persistence.view.testsuite.embedded.entity;

import com.blazebit.persistence.CriteriaBuilder;
import com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66;
import com.blazebit.persistence.view.EntityViewManager;
import com.blazebit.persistence.view.EntityViewSetting;
import com.blazebit.persistence.view.EntityViews;
Expand All @@ -28,6 +29,7 @@
import com.blazebit.persistence.testsuite.entity.Document;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.List;

Expand Down Expand Up @@ -78,7 +80,9 @@ public void multipleEmbeddingsProduceCorrectResults() {
assertEquals("doc2", results.get(1).getEmbeddedDetails().getName());
}

// NOTE: Hibernate ORM 6.6.1 has a bug: https://hibernate.atlassian.net/browse/HHH-18773
@Test
@Category(NoHibernate66.class)
public void filteringOnEmbeddedAttributeWorks() {
CriteriaBuilder<Document> criteria = cbf.create(em, Document.class, "e")
.orderByAsc("id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void testUpdateAddNewEntityToCollection() {
AssertStatementBuilder builder = assertUnorderedQuerySequence();
fullFetch(builder);

if (version) {
if (!doesTransientCheckBeforeFlush() && version) {
versionUpdate(builder);
}
builder.validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void testUpdateAddNewEntityToCollection() {
}
} else {
fullFetch(builder);
if (version) {
if (!doesTransientCheckBeforeFlush() && version) {
versionUpdate(builder);
}
}
Expand Down
2 changes: 1 addition & 1 deletion integration/deltaspike-data/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@
<id>hibernate-6.6</id>
<!-- Note that we compile the test suite against Hibernate 5.6 because this testsuite will be jakarta-transformed -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.hibernate.ScrollMode;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
Expand Down Expand Up @@ -117,7 +116,6 @@
import org.hibernate.sql.exec.spi.JdbcParameterBinder;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.exec.spi.JdbcParametersList;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.internal.RowTransformerJpaTupleImpl;
import org.hibernate.sql.results.internal.RowTransformerSingularReturnImpl;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
Expand Down Expand Up @@ -592,10 +590,6 @@ public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T
realJdbcSelect,
jdbcParameterBindings,
new SqmJdbcExecutionContextAdapter(executionContext, jdbcSelect) {
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
// subSelectFetchKeyHandler.addKey( entityKey );
}

@Override
public String getQueryIdentifier(String sql) {
return sql;
Expand Down Expand Up @@ -1099,9 +1093,6 @@ public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T
jdbcSelect.getLimitParameter()
);
ExecutionContext executionContext = new SqmJdbcExecutionContextAdapter(domainQueryExecutionContext, realJdbcSelect) {
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
// subSelectFetchKeyHandler.addKey( entityKey, entry );
}

@Override
public String getQueryIdentifier(String sql) {
Expand All @@ -1115,11 +1106,6 @@ public boolean hasQueryExecutionToBeAddedToStatistics() {
};
// ExecutionContext executionContext = new ExecutionContext() {
// @Override
// public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
//// subSelectFetchKeyHandler.addKey( entityKey, entry );
// }
//
// @Override
// public SharedSessionContractImplementor getSession() {
// return domainQueryExecutionContext.getSession();
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ReturnableType<?> resolveFunctionReturnType(
ReturnableType<?> impliedType,
List<? extends SqmTypedNode<?>> arguments,
TypeConfiguration typeConfiguration) {
return resolveFunctionReturnType(impliedType, null, arguments, typeConfiguration);
return resolveFunctionReturnType(impliedType, (Supplier<MappingModelExpressible<?>>) null, arguments, typeConfiguration);
}

public ReturnableType<?> resolveFunctionReturnType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.query.sqm.tree.SqmVisitableNode;
Expand All @@ -41,6 +42,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
*
Expand All @@ -50,6 +52,7 @@
public class HibernateSqmFunctionDescriptorAdapter implements JpqlFunction {

private static final Method GENERATE_SQM_EXPRESSION;
private static final Method RESOLVE_FUNCTION_RETURN_TYPE;
private static final Constructor<QueryLiteral> QUERY_LITERAL_CONSTRUCTOR;

static {
Expand All @@ -64,6 +67,17 @@ public class HibernateSqmFunctionDescriptorAdapter implements JpqlFunction {
}
}
GENERATE_SQM_EXPRESSION = generateSqmExpression;
Method resolveFunctionReturnType;
try {
resolveFunctionReturnType = FunctionReturnTypeResolver.class.getMethod("resolveFunctionReturnType", ReturnableType.class, Supplier.class, List.class, TypeConfiguration.class);
} catch (NoSuchMethodException e1) {
try {
resolveFunctionReturnType = FunctionReturnTypeResolver.class.getMethod("resolveFunctionReturnType", ReturnableType.class, List.class, TypeConfiguration.class);
} catch (NoSuchMethodException e2) {
throw new RuntimeException("Could not find method to resolve function return type. Please report your version of hibernate so we can provide support for it!", e1);
}
}
RESOLVE_FUNCTION_RETURN_TYPE = resolveFunctionReturnType;
Constructor<QueryLiteral> queryLiteralConstructor;
try {
queryLiteralConstructor = QueryLiteral.class.getConstructor(Object.class, SqlExpressible.class);
Expand Down Expand Up @@ -130,18 +144,44 @@ public Class<Object> getJavaType() {
List<SqmTypedNode<?>> arguments = new ArrayList<>(1);
arguments.add(new CustomSqmTypedNode<>(type));
if ( function instanceof AbstractSqmFunctionDescriptor ) {
ReturnableType<?> returnableType = ((AbstractSqmFunctionDescriptor) function).getReturnTypeResolver().resolveFunctionReturnType(
null,
arguments,
sfi.getTypeConfiguration()
);
if (returnableType != null) {
return returnableType.getBindableJavaType();
try {
FunctionReturnTypeResolver returnTypeResolver = ((AbstractSqmFunctionDescriptor) function).getReturnTypeResolver();
ReturnableType<?> returnableType;
if (RESOLVE_FUNCTION_RETURN_TYPE.getParameterCount() == 4) {
returnableType = (ReturnableType<?>) RESOLVE_FUNCTION_RETURN_TYPE.invoke(
returnTypeResolver,
null,
null,
arguments,
sfi.getTypeConfiguration()
);
} else {
returnableType = (ReturnableType<?>) RESOLVE_FUNCTION_RETURN_TYPE.invoke(
returnTypeResolver,
null,
arguments,
sfi.getTypeConfiguration()
);
}
if (returnableType != null) {
return returnableType.getBindableJavaType();
}
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not resolve function return type. Please report your version of hibernate so we can provide support for it!", e);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof RuntimeException) {
throw (RuntimeException) e.getTargetException();
}
throw new RuntimeException("Could not resolve function return type", e);
}
}
try {
SqmExpressible<?> expressionType = ((SelfRenderingSqmFunction<?>) GENERATE_SQM_EXPRESSION.invoke(function, arguments, null, sfi.getQueryEngine(), sfi.getTypeConfiguration()))
.getNodeType();
SqmExpressible<?> expressionType;
if (GENERATE_SQM_EXPRESSION.getParameterCount() == 4) {
expressionType = ((SelfRenderingSqmFunction<?>) GENERATE_SQM_EXPRESSION.invoke(function, arguments, null, sfi.getQueryEngine(), sfi.getTypeConfiguration())).getNodeType();
} else {
expressionType = ((SelfRenderingSqmFunction<?>) GENERATE_SQM_EXPRESSION.invoke(function, arguments, null, sfi.getQueryEngine())).getNodeType();
}
return expressionType == null ? null : expressionType.getBindableJavaType();
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not generate SQM expression for function. Please report your version of hibernate so we can provide support for it!", e);
Expand Down
2 changes: 1 addition & 1 deletion integration/quarkus-3/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@
<id>hibernate-6.6</id>
<!-- Note that we still run against 6.2 because Quarkus doesn't support 6.6 yet -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernatecom.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion integration/querydsl/testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@
<id>hibernate-6.6</id>
<!-- Note that we compile the test suite against Hibernate 5.6 because this testsuite will be jakarta-transformed -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion integration/spring-data/testsuite/webflux/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@
<id>hibernate-6.6</id>
<!-- Note that we compile the test suite against Hibernate 5.6 because this testsuite will be jakarta-transformed -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
<spring.activeProfiles>hibernate</spring.activeProfiles>
</properties>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion integration/spring-data/testsuite/webmvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@
<id>hibernate-6.6</id>
<!-- Note that we compile the test suite against Hibernate 5.6 because this testsuite will be jakarta-transformed -->
<properties>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
<spring.activeProfiles>hibernate</spring.activeProfiles>
</properties>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jpa-criteria/testsuite-jakarta-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
<id>hibernate-6.6</id>
<properties>
<jpa-api-version>${version.jakarta-jpa-3.1-api}</jpa-api-version>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60</jpa.excludedGroups>
<jpa.excludedGroups>com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate60,com.blazebit.persistence.testsuite.base.jpa.category.NoHibernate66</jpa.excludedGroups>
</properties>
<dependencies>
<dependency>
Expand Down
Loading

0 comments on commit c2b6c31

Please sign in to comment.