From 4ec960e6fe75dd10db746a717d673cd11ba925d7 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Wed, 23 Apr 2025 18:51:45 -0400 Subject: [PATCH 01/13] Implement visitBooleanExpressionPredicate --- .../SimpleSelectQueryIntegrationTests.java | 14 +++++++++++++ .../translate/AbstractMqlTranslator.java | 20 ++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java index 2eede1df..c63ff5cf 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java @@ -16,6 +16,7 @@ package com.mongodb.hibernate.query.select; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -401,6 +402,19 @@ void testBigDecimal() { "{'aggregate': 'books', 'pipeline': [{'$match': {'price': {'$eq': {'$numberDecimal': '123.50'}}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testBooleanFieldAsPredicate(boolean negated) { + assertSelectionQuery( + "from Book where " + (negated ? "not " : "") + "outOfStock", + Book.class, + null, + "{'aggregate': 'books', 'pipeline': [{'$match': {'outOfStock': {'$eq': " + + (negated ? "false" : "true") + + "}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", + negated ? emptyList() : singletonList(testingBook)); + } } private void assertSelectionQuery( diff --git a/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java b/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java index 8656104f..f79afd62 100644 --- a/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java +++ b/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java @@ -498,6 +498,21 @@ public void visitUnparsedNumericLiteral(UnparsedNumericLitera FIELD_VALUE, new AstLiteralValue(toBsonValue(unparsedNumericLiteral.getLiteralValue()))); } + @Override + public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) { + if (!isFieldPathExpression(booleanExpressionPredicate.getExpression())) { + throw new FeatureNotSupportedException("Currently only field path expression is supported"); + } + var fieldPath = acceptAndYield(booleanExpressionPredicate.getExpression(), FIELD_PATH); + var astFilterOperation = new AstComparisonFilterOperation( + EQ, + booleanExpressionPredicate.isNegated() + ? new AstLiteralValue(BsonBoolean.FALSE) + : new AstLiteralValue(BsonBoolean.TRUE)); + var filter = new AstFieldOperationFilter(new AstFilterFieldPath(fieldPath), astFilterOperation); + astVisitorValueHolder.yield(FILTER, filter); + } + @Override public void visitDeleteStatement(DeleteStatement deleteStatement) { throw new FeatureNotSupportedException("TODO-HIBERNATE-46 https://jira.mongodb.org/browse/HIBERNATE-46"); @@ -693,11 +708,6 @@ public void visitModifiedSubQueryExpression(ModifiedSubQueryExpression modifiedS throw new FeatureNotSupportedException(); } - @Override - public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) { - throw new FeatureNotSupportedException(); - } - @Override public void visitBetweenPredicate(BetweenPredicate betweenPredicate) { throw new FeatureNotSupportedException(); From 90ff011bfed6882129163172100d045ef8571fdb Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Tue, 29 Apr 2025 15:26:52 -0400 Subject: [PATCH 02/13] refactor testing case out of SimpleSelectQueryIntegrationTests#QueryLiteralTests --- ...bstractSelectionQueryIntegrationTests.java | 110 ++++++++++++++++++ .../mongodb/hibernate/query/select/Book.java | 19 ++- ...anExpressionPredicateTranslatingTests.java | 62 ++++++++++ .../SimpleSelectQueryIntegrationTests.java | 96 +-------------- .../translate/AbstractMqlTranslator.java | 11 +- .../translate/mongoast/AstLiteralValue.java | 4 + 6 files changed, 191 insertions(+), 111 deletions(-) create mode 100644 src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java create mode 100644 src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java new file mode 100644 index 00000000..b42aa1f9 --- /dev/null +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -0,0 +1,110 @@ +/* + * Copyright 2025-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mongodb.hibernate.query.select; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.mongodb.hibernate.TestCommandListener; +import com.mongodb.hibernate.junit.MongoExtension; +import java.util.List; +import java.util.function.Consumer; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.bson.BsonDocument; +import org.hibernate.query.SelectionQuery; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.hibernate.testing.orm.junit.ServiceRegistryScopeAware; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.SessionFactoryScopeAware; +import org.junit.jupiter.api.extension.ExtendWith; + +@SessionFactory(exportSchema = false) +@ExtendWith(MongoExtension.class) +abstract class AbstractSelectionQueryIntegrationTests implements SessionFactoryScopeAware, ServiceRegistryScopeAware { + + SessionFactoryScope sessionFactoryScope; + + TestCommandListener testCommandListener; + + @Override + public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) { + this.sessionFactoryScope = sessionFactoryScope; + } + + @Override + public void injectServiceRegistryScope(ServiceRegistryScope serviceRegistryScope) { + this.testCommandListener = serviceRegistryScope.getRegistry().requireService(TestCommandListener.class); + } + + void assertSelectionQuery( + String hql, + Class resultType, + Consumer> queryPostProcessor, + String expectedMql, + List expectedResultList) { + assertSelectionQuery(hql, resultType, queryPostProcessor, expectedMql, resultList -> assertThat(resultList) + .usingRecursiveFieldByFieldElementComparator() + .containsExactlyElementsOf(expectedResultList)); + } + + void assertSelectionQuery( + String hql, + Class resultType, + Consumer> queryPostProcessor, + String expectedMql, + Consumer> resultListVerifier) { + sessionFactoryScope.inTransaction(session -> { + var selectionQuery = session.createSelectionQuery(hql, resultType); + if (queryPostProcessor != null) { + queryPostProcessor.accept(selectionQuery); + } + var resultList = selectionQuery.getResultList(); + + assertActualCommand(BsonDocument.parse(expectedMql)); + + resultListVerifier.accept(resultList); + }); + } + + void assertSelectQueryFailure( + String hql, + Class resultType, + Consumer> queryPostProcessor, + Class expectedExceptionType, + String expectedExceptionMessage, + Object... expectedExceptionMessageParameters) { + sessionFactoryScope.inTransaction(session -> assertThatThrownBy(() -> { + var selectionQuery = session.createSelectionQuery(hql, resultType); + if (queryPostProcessor != null) { + queryPostProcessor.accept(selectionQuery); + } + selectionQuery.getResultList(); + }) + .isInstanceOf(expectedExceptionType) + .hasMessage(expectedExceptionMessage, expectedExceptionMessageParameters)); + } + + void assertActualCommand(BsonDocument expectedCommand) { + var capturedCommands = testCommandListener.getStartedCommands(); + + assertThat(capturedCommands) + .singleElement() + .asInstanceOf(InstanceOfAssertFactories.MAP) + .containsAllEntriesOf(expectedCommand); + } +} diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java index 82e8ef62..4ffc3d9f 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java @@ -16,26 +16,23 @@ package com.mongodb.hibernate.query.select; -import com.mongodb.hibernate.annotations.ObjectIdGenerator; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import java.math.BigDecimal; -import org.bson.types.ObjectId; @Entity(name = "Book") @Table(name = "books") public class Book { @Id - @ObjectIdGenerator - ObjectId id; + int id; - public Book() {} + Book() {} - String title; - Boolean outOfStock; - Integer publishYear; - Long isbn13; - Double discount; - BigDecimal price; + String title = ""; + Boolean outOfStock = false; + Integer publishYear = 0; + Long isbn13 = 0L; + Double discount = 0.0D; + BigDecimal price = new BigDecimal("0.0"); } diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java new file mode 100644 index 00000000..c11d67d2 --- /dev/null +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java @@ -0,0 +1,62 @@ +/* + * Copyright 2025-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mongodb.hibernate.query.select; + +import static java.util.Collections.singletonList; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@DomainModel(annotatedClasses = Book.class) +class BooleanExpressionPredicateTranslatingTests extends AbstractSelectionQueryIntegrationTests { + + private Book bookOutOfStock; + private Book bookInStock; + + @BeforeEach + void beforeEach() { + bookOutOfStock = new Book(); + bookOutOfStock.id = 1; + bookOutOfStock.outOfStock = true; + + bookInStock = new Book(); + bookInStock.id = 2; + bookInStock.outOfStock = false; + + sessionFactoryScope.inTransaction(session -> { + session.persist(bookOutOfStock); + session.persist(bookInStock); + }); + + testCommandListener.clear(); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testBooleanExpressionPredicateTranslating(boolean negated) { + assertSelectionQuery( + "from Book where" + (negated ? " not " : " ") + "outOfStock", + Book.class, + null, + "{'aggregate': 'books', 'pipeline': [{'$match': {'outOfStock': {'$eq': " + + (negated ? "false" : "true") + + "}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", + negated ? singletonList(bookInStock) : singletonList(bookOutOfStock)); + } +} diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java index c63ff5cf..3b316516 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java @@ -16,56 +16,25 @@ package com.mongodb.hibernate.query.select; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import com.mongodb.hibernate.TestCommandListener; import com.mongodb.hibernate.internal.FeatureNotSupportedException; -import com.mongodb.hibernate.junit.MongoExtension; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import java.math.BigDecimal; import java.util.Arrays; import java.util.List; -import java.util.function.Consumer; -import org.assertj.core.api.InstanceOfAssertFactories; -import org.bson.BsonDocument; -import org.hibernate.query.SelectionQuery; import org.hibernate.query.SemanticException; import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.hibernate.testing.orm.junit.ServiceRegistryScopeAware; -import org.hibernate.testing.orm.junit.SessionFactory; -import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.SessionFactoryScopeAware; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -@SessionFactory(exportSchema = false) @DomainModel(annotatedClasses = {SimpleSelectQueryIntegrationTests.Contact.class, Book.class}) -@ExtendWith(MongoExtension.class) -class SimpleSelectQueryIntegrationTests implements SessionFactoryScopeAware, ServiceRegistryScopeAware { - - private SessionFactoryScope sessionFactoryScope; - - private TestCommandListener testCommandListener; - - @Override - public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) { - this.sessionFactoryScope = sessionFactoryScope; - } - - @Override - public void injectServiceRegistryScope(ServiceRegistryScope serviceRegistryScope) { - this.testCommandListener = serviceRegistryScope.getRegistry().requireService(TestCommandListener.class); - } +class SimpleSelectQueryIntegrationTests extends AbstractSelectionQueryIntegrationTests { @Nested class QueryTests { @@ -82,7 +51,7 @@ private static List getTestingContacts(int... ids) { .mapToObj(id -> testingContacts.stream() .filter(c -> c.id == id) .findFirst() - .orElseThrow(() -> new IllegalArgumentException("id not exists: " + id))) + .orElseThrow(() -> new IllegalArgumentException("id does not exist: " + id))) .toList(); } @@ -402,67 +371,6 @@ void testBigDecimal() { "{'aggregate': 'books', 'pipeline': [{'$match': {'price': {'$eq': {'$numberDecimal': '123.50'}}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } - - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void testBooleanFieldAsPredicate(boolean negated) { - assertSelectionQuery( - "from Book where " + (negated ? "not " : "") + "outOfStock", - Book.class, - null, - "{'aggregate': 'books', 'pipeline': [{'$match': {'outOfStock': {'$eq': " - + (negated ? "false" : "true") - + "}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", - negated ? emptyList() : singletonList(testingBook)); - } - } - - private void assertSelectionQuery( - String hql, - Class resultType, - Consumer> queryPostProcessor, - String expectedMql, - List expectedResultList) { - sessionFactoryScope.inTransaction(session -> { - var selectionQuery = session.createSelectionQuery(hql, resultType); - if (queryPostProcessor != null) { - queryPostProcessor.accept(selectionQuery); - } - var resultList = selectionQuery.getResultList(); - - assertActualCommand(BsonDocument.parse(expectedMql)); - - assertThat(resultList) - .usingRecursiveFieldByFieldElementComparator() - .containsExactlyElementsOf(expectedResultList); - }); - } - - private void assertSelectQueryFailure( - String hql, - Class resultType, - Consumer> queryPostProcessor, - Class expectedExceptionType, - String expectedExceptionMessage, - Object... expectedExceptionMessageParameters) { - sessionFactoryScope.inTransaction(session -> assertThatThrownBy(() -> { - var selectionQuery = session.createSelectionQuery(hql, resultType); - if (queryPostProcessor != null) { - queryPostProcessor.accept(selectionQuery); - } - selectionQuery.getResultList(); - }) - .isInstanceOf(expectedExceptionType) - .hasMessage(expectedExceptionMessage, expectedExceptionMessageParameters)); - } - - private void assertActualCommand(BsonDocument expectedCommand) { - var capturedCommands = testCommandListener.getStartedCommands(); - - assertThat(capturedCommands) - .singleElement() - .asInstanceOf(InstanceOfAssertFactories.MAP) - .containsAllEntriesOf(expectedCommand); } @Entity(name = "Contact") diff --git a/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java b/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java index f79afd62..261e69e0 100644 --- a/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java +++ b/src/main/java/com/mongodb/hibernate/internal/translate/AbstractMqlTranslator.java @@ -27,6 +27,8 @@ import static com.mongodb.hibernate.internal.translate.AstVisitorValueDescriptor.FIELD_VALUE; import static com.mongodb.hibernate.internal.translate.AstVisitorValueDescriptor.FILTER; import static com.mongodb.hibernate.internal.translate.AstVisitorValueDescriptor.PROJECT_STAGE_SPECIFICATIONS; +import static com.mongodb.hibernate.internal.translate.mongoast.AstLiteralValue.FALSE; +import static com.mongodb.hibernate.internal.translate.mongoast.AstLiteralValue.TRUE; import static com.mongodb.hibernate.internal.translate.mongoast.filter.AstComparisonFilterOperator.EQ; import static com.mongodb.hibernate.internal.translate.mongoast.filter.AstComparisonFilterOperator.GT; import static com.mongodb.hibernate.internal.translate.mongoast.filter.AstComparisonFilterOperator.GTE; @@ -501,14 +503,11 @@ public void visitUnparsedNumericLiteral(UnparsedNumericLitera @Override public void visitBooleanExpressionPredicate(BooleanExpressionPredicate booleanExpressionPredicate) { if (!isFieldPathExpression(booleanExpressionPredicate.getExpression())) { - throw new FeatureNotSupportedException("Currently only field path expression is supported"); + throw new FeatureNotSupportedException("Expression not of field path not supported"); } var fieldPath = acceptAndYield(booleanExpressionPredicate.getExpression(), FIELD_PATH); - var astFilterOperation = new AstComparisonFilterOperation( - EQ, - booleanExpressionPredicate.isNegated() - ? new AstLiteralValue(BsonBoolean.FALSE) - : new AstLiteralValue(BsonBoolean.TRUE)); + var astFilterOperation = + new AstComparisonFilterOperation(EQ, booleanExpressionPredicate.isNegated() ? FALSE : TRUE); var filter = new AstFieldOperationFilter(new AstFilterFieldPath(fieldPath), astFilterOperation); astVisitorValueHolder.yield(FILTER, filter); } diff --git a/src/main/java/com/mongodb/hibernate/internal/translate/mongoast/AstLiteralValue.java b/src/main/java/com/mongodb/hibernate/internal/translate/mongoast/AstLiteralValue.java index f5f721d0..7c45ea9e 100644 --- a/src/main/java/com/mongodb/hibernate/internal/translate/mongoast/AstLiteralValue.java +++ b/src/main/java/com/mongodb/hibernate/internal/translate/mongoast/AstLiteralValue.java @@ -16,6 +16,7 @@ package com.mongodb.hibernate.internal.translate.mongoast; +import org.bson.BsonBoolean; import org.bson.BsonValue; import org.bson.BsonWriter; import org.bson.codecs.BsonValueCodec; @@ -27,6 +28,9 @@ public record AstLiteralValue(BsonValue literalValue) implements AstValue { private static final EncoderContext DEFAULT_CONTEXT = EncoderContext.builder().build(); + public static final AstLiteralValue TRUE = new AstLiteralValue(BsonBoolean.TRUE); + public static final AstLiteralValue FALSE = new AstLiteralValue(BsonBoolean.FALSE); + @Override public void render(BsonWriter writer) { BSON_VALUE_CODEC.encode(writer, literalValue, DEFAULT_CONTEXT); From b30fb2d5d4b37185950bb3295d211a94cf79a8c8 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Tue, 29 Apr 2025 16:05:19 -0400 Subject: [PATCH 03/13] add "unsupported" testing case --- ...ooleanExpressionPredicateTranslatingTests.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java index c11d67d2..fa7aa4f8 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java @@ -18,8 +18,10 @@ import static java.util.Collections.singletonList; +import com.mongodb.hibernate.internal.FeatureNotSupportedException; import org.hibernate.testing.orm.junit.DomainModel; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -49,7 +51,7 @@ void beforeEach() { @ParameterizedTest @ValueSource(booleans = {true, false}) - void testBooleanExpressionPredicateTranslating(boolean negated) { + void testBooleanFieldPathExpression(boolean negated) { assertSelectionQuery( "from Book where" + (negated ? " not " : " ") + "outOfStock", Book.class, @@ -59,4 +61,15 @@ void testBooleanExpressionPredicateTranslating(boolean negated) { + "}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", negated ? singletonList(bookInStock) : singletonList(bookOutOfStock)); } + + @Test + void testNonFieldPathExpressionNotSupported() { + assertSelectQueryFailure( + "from Book where true", + Book.class, + null, + FeatureNotSupportedException.class, + "Expression not of field path not supported" + ); + } } From 4fa0376c72b7ae256f56aac8a0c9591b2942b403 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 2 May 2025 15:36:38 -0400 Subject: [PATCH 04/13] Update src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java Co-authored-by: Viacheslav Babanin --- .../query/select/AbstractSelectionQueryIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index b42aa1f9..dfba6567 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -39,7 +39,7 @@ abstract class AbstractSelectionQueryIntegrationTests implements SessionFactoryS SessionFactoryScope sessionFactoryScope; - TestCommandListener testCommandListener; + protected TestCommandListener testCommandListener; @Override public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) { From a980f21c166de5005508cef2d6218d22d28616ef Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 2 May 2025 15:38:02 -0400 Subject: [PATCH 05/13] Update src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java Co-authored-by: Viacheslav Babanin --- .../BooleanExpressionPredicateTranslatingTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java index fa7aa4f8..0691141d 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java @@ -62,14 +62,14 @@ void testBooleanFieldPathExpression(boolean negated) { negated ? singletonList(bookInStock) : singletonList(bookOutOfStock)); } - @Test - void testNonFieldPathExpressionNotSupported() { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testNonFieldPathExpressionNotSupported(final boolean booleanLiteral) { assertSelectQueryFailure( - "from Book where true", + "from Book where " + booleanLiteral, Book.class, null, FeatureNotSupportedException.class, "Expression not of field path not supported" ); - } } From 2e325c538817ab30cc2d0da3c942e7c965623612 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 2 May 2025 15:40:11 -0400 Subject: [PATCH 06/13] revert back Book.id type refactoring for it is unnecessary --- .../select/AbstractSelectionQueryIntegrationTests.java | 2 +- .../java/com/mongodb/hibernate/query/select/Book.java | 5 ++++- .../BooleanExpressionPredicateTranslatingTests.java | 9 +++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index dfba6567..a0409bd2 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -37,7 +37,7 @@ @ExtendWith(MongoExtension.class) abstract class AbstractSelectionQueryIntegrationTests implements SessionFactoryScopeAware, ServiceRegistryScopeAware { - SessionFactoryScope sessionFactoryScope; + protected SessionFactoryScope sessionFactoryScope; protected TestCommandListener testCommandListener; diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java index 4ffc3d9f..c0f92706 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/Book.java @@ -16,16 +16,19 @@ package com.mongodb.hibernate.query.select; +import com.mongodb.hibernate.annotations.ObjectIdGenerator; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import java.math.BigDecimal; +import org.bson.types.ObjectId; @Entity(name = "Book") @Table(name = "books") public class Book { @Id - int id; + @ObjectIdGenerator + ObjectId id; Book() {} diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java index 0691141d..921bd49a 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java @@ -21,7 +21,6 @@ import com.mongodb.hibernate.internal.FeatureNotSupportedException; import org.hibernate.testing.orm.junit.DomainModel; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -34,11 +33,9 @@ class BooleanExpressionPredicateTranslatingTests extends AbstractSelectionQueryI @BeforeEach void beforeEach() { bookOutOfStock = new Book(); - bookOutOfStock.id = 1; bookOutOfStock.outOfStock = true; bookInStock = new Book(); - bookInStock.id = 2; bookInStock.outOfStock = false; sessionFactoryScope.inTransaction(session -> { @@ -62,7 +59,7 @@ void testBooleanFieldPathExpression(boolean negated) { negated ? singletonList(bookInStock) : singletonList(bookOutOfStock)); } - @ParameterizedTest + @ParameterizedTest @ValueSource(booleans = {true, false}) void testNonFieldPathExpressionNotSupported(final boolean booleanLiteral) { assertSelectQueryFailure( @@ -70,6 +67,6 @@ void testNonFieldPathExpressionNotSupported(final boolean booleanLiteral) { Book.class, null, FeatureNotSupportedException.class, - "Expression not of field path not supported" - ); + "Expression not of field path not supported"); + } } From aa987b5b7f1db6642b0b5e4460712466bb007de0 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 2 May 2025 15:47:20 -0400 Subject: [PATCH 07/13] rename BooleanExpressionPredicateTranslatingTests to BooleanExpressionWhereClauseIntegrationTests --- .../select/BooleanExpressionPredicateTranslatingTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java index 921bd49a..a5537632 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java @@ -25,11 +25,12 @@ import org.junit.jupiter.params.provider.ValueSource; @DomainModel(annotatedClasses = Book.class) -class BooleanExpressionPredicateTranslatingTests extends AbstractSelectionQueryIntegrationTests { +class BooleanExpressionWhereClauseIntegrationTests extends AbstractSelectionQueryIntegrationTests { private Book bookOutOfStock; private Book bookInStock; + @BeforeEach void beforeEach() { bookOutOfStock = new Book(); From 48d2c27582169c7ca9ea4f328a0abd3e9a49f7d7 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 2 May 2025 15:51:21 -0400 Subject: [PATCH 08/13] make fields in AbstractSelectionQueryIntegrationTests private and add protected access methods --- .../AbstractSelectionQueryIntegrationTests.java | 12 ++++++++++-- ...ooleanExpressionWhereClauseIntegrationTests.java} | 5 ++--- .../select/SimpleSelectQueryIntegrationTests.java | 8 ++++---- 3 files changed, 16 insertions(+), 9 deletions(-) rename src/integrationTest/java/com/mongodb/hibernate/query/select/{BooleanExpressionPredicateTranslatingTests.java => BooleanExpressionWhereClauseIntegrationTests.java} (96%) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index a0409bd2..07abbc67 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -37,9 +37,17 @@ @ExtendWith(MongoExtension.class) abstract class AbstractSelectionQueryIntegrationTests implements SessionFactoryScopeAware, ServiceRegistryScopeAware { - protected SessionFactoryScope sessionFactoryScope; + private SessionFactoryScope sessionFactoryScope; - protected TestCommandListener testCommandListener; + private TestCommandListener testCommandListener; + + protected SessionFactoryScope getSessionFactoryScope() { + return sessionFactoryScope; + } + + protected TestCommandListener getTestCommandListener() { + return testCommandListener; + } @Override public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) { diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java similarity index 96% rename from src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java rename to src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java index a5537632..6647ef8d 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionPredicateTranslatingTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java @@ -30,7 +30,6 @@ class BooleanExpressionWhereClauseIntegrationTests extends AbstractSelectionQuer private Book bookOutOfStock; private Book bookInStock; - @BeforeEach void beforeEach() { bookOutOfStock = new Book(); @@ -39,12 +38,12 @@ void beforeEach() { bookInStock = new Book(); bookInStock.outOfStock = false; - sessionFactoryScope.inTransaction(session -> { + getSessionFactoryScope().inTransaction(session -> { session.persist(bookOutOfStock); session.persist(bookInStock); }); - testCommandListener.clear(); + getTestCommandListener().clear(); } @ParameterizedTest diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java index 3b316516..7bda9362 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java @@ -57,8 +57,8 @@ private static List getTestingContacts(int... ids) { @BeforeEach void beforeEach() { - sessionFactoryScope.inTransaction(session -> testingContacts.forEach(session::persist)); - testCommandListener.clear(); + getSessionFactoryScope().inTransaction(session -> testingContacts.forEach(session::persist)); + getTestCommandListener().clear(); } @ParameterizedTest @@ -307,9 +307,9 @@ void beforeEach() { testingBook.isbn13 = 9780310904168L; testingBook.discount = 0.25; testingBook.price = new BigDecimal("123.50"); - sessionFactoryScope.inTransaction(session -> session.persist(testingBook)); + getSessionFactoryScope().inTransaction(session -> session.persist(testingBook)); - testCommandListener.clear(); + getTestCommandListener().clear(); } @Test From b420a2d00b0409481e73218b99356c0110b27809 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 2 May 2025 15:58:40 -0400 Subject: [PATCH 09/13] introduce query assertion over-loaded methods omitting query post processor --- ...bstractSelectionQueryIntegrationTests.java | 24 +++++++++++++++++++ ...ExpressionWhereClauseIntegrationTests.java | 2 -- .../SimpleSelectQueryIntegrationTests.java | 15 ------------ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index 07abbc67..b486ecae 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -70,6 +70,10 @@ void assertSelectionQuery( .containsExactlyElementsOf(expectedResultList)); } + void assertSelectionQuery(String hql, Class resultType, String expectedMql, List expectedResultList) { + assertSelectionQuery(hql, resultType, null, expectedMql, expectedResultList); + } + void assertSelectionQuery( String hql, Class resultType, @@ -89,6 +93,11 @@ void assertSelectionQuery( }); } + void assertSelectionQuery( + String hql, Class resultType, String expectedMql, Consumer> resultListVerifier) { + assertSelectionQuery(hql, resultType, null, expectedMql, resultListVerifier); + } + void assertSelectQueryFailure( String hql, Class resultType, @@ -107,6 +116,21 @@ void assertSelectQueryFailure( .hasMessage(expectedExceptionMessage, expectedExceptionMessageParameters)); } + void assertSelectQueryFailure( + String hql, + Class resultType, + Class expectedExceptionType, + String expectedExceptionMessage, + Object... expectedExceptionMessageParameters) { + assertSelectQueryFailure( + hql, + resultType, + null, + expectedExceptionType, + expectedExceptionMessage, + expectedExceptionMessageParameters); + } + void assertActualCommand(BsonDocument expectedCommand) { var capturedCommands = testCommandListener.getStartedCommands(); diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java index 6647ef8d..2bdb7d5e 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/BooleanExpressionWhereClauseIntegrationTests.java @@ -52,7 +52,6 @@ void testBooleanFieldPathExpression(boolean negated) { assertSelectionQuery( "from Book where" + (negated ? " not " : " ") + "outOfStock", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'outOfStock': {'$eq': " + (negated ? "false" : "true") + "}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", @@ -65,7 +64,6 @@ void testNonFieldPathExpressionNotSupported(final boolean booleanLiteral) { assertSelectQueryFailure( "from Book where " + booleanLiteral, Book.class, - null, FeatureNotSupportedException.class, "Expression not of field path not supported"); } diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java index 7bda9362..dc55c828 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java @@ -152,7 +152,6 @@ void testSingleNegation() { assertSelectionQuery( "from Contact where age > 18 and not (country = 'USA')", Contact.class, - null, "{'aggregate': 'contacts', 'pipeline': [{'$match': {'$and': [{'age': {'$gt': 18}}, {'$nor': [{'country': {'$eq': 'USA'}}]}]}}, {'$project': {'_id': true, 'age': true, 'country': true, 'name': true}}]}", getTestingContacts(2, 4)); } @@ -162,7 +161,6 @@ void testSingleNegationWithAnd() { assertSelectionQuery( "from Contact where not (country = 'USA' and age > 18)", Contact.class, - null, "{'aggregate': 'contacts', 'pipeline': [{'$match': {'$nor': [{'$and': [{'country': {'$eq': 'USA'}}, {'age': {'$gt': {'$numberInt': '18'}}}]}]}}, {'$project': {'_id': true, 'age': true, 'country': true, 'name': true}}]}", getTestingContacts(1, 2, 3, 4)); } @@ -172,7 +170,6 @@ void testSingleNegationWithOr() { assertSelectionQuery( "from Contact where not (country = 'USA' or age > 18)", Contact.class, - null, "{'aggregate': 'contacts', 'pipeline': [{'$match': {'$nor': [{'$or': [{'country': {'$eq': 'USA'}}, {'age': {'$gt': {'$numberInt': '18'}}}]}]}}, {'$project': {'_id': true, 'age': true, 'country': true, 'name': true}}]}", getTestingContacts(3)); } @@ -182,7 +179,6 @@ void testSingleNegationWithAndOr() { assertSelectionQuery( "from Contact where not (country = 'USA' and age > 18 or age < 25)", Contact.class, - null, "{'aggregate': 'contacts', 'pipeline': [{'$match': {'$nor': [{'$or': [{'$and': [{'country': {'$eq': 'USA'}}, {'age': {'$gt': {'$numberInt': '18'}}}]}," + " {'age': {'$lt': {'$numberInt': '25'}}}]}]}}, {'$project': {'_id': true, 'age': true, 'country': true, 'name': true}}]}", getTestingContacts(2, 4)); @@ -193,7 +189,6 @@ void testDoubleNegation() { assertSelectionQuery( "from Contact where age > 18 and not ( not (country = 'USA') )", Contact.class, - null, "{'aggregate': 'contacts', 'pipeline': [{'$match': {'$and': [{'age': {'$gt': 18}}, {'$nor': [{'$nor': [{'country': {'$eq': 'USA'}}]}]}]}}, {'$project': {'_id': true, 'age': true, 'country': true, 'name': true}}]}", getTestingContacts(5)); } @@ -223,7 +218,6 @@ void testProjectUsingWrongAlias() { assertSelectQueryFailure( "select k.name, c.age from Contact as c where c.country = :country", Contact.class, - null, SemanticException.class, "Could not interpret path expression '%s'", "k.name"); @@ -237,7 +231,6 @@ void testComparisonBetweenFieldAndNonValueNotSupported1() { assertSelectQueryFailure( "from Contact as c where c.age = c.id + 1", Contact.class, - null, FeatureNotSupportedException.class, "Only the following comparisons are supported: field vs literal, field vs parameter"); } @@ -247,7 +240,6 @@ void testComparisonBetweenValuesNotSupported() { assertSelectQueryFailure( "from Contact where 1 = 1", Contact.class, - null, FeatureNotSupportedException.class, "Only the following comparisons are supported: field vs literal, field vs parameter"); } @@ -257,7 +249,6 @@ void testComparisonBetweenFieldsNotSupported() { assertSelectQueryFailure( "from Contact where age = id", Contact.class, - null, FeatureNotSupportedException.class, "Only the following comparisons are supported: field vs literal, field vs parameter"); } @@ -317,7 +308,6 @@ void testBoolean() { assertSelectionQuery( "from Book where outOfStock = true", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'outOfStock': {'$eq': true}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } @@ -327,7 +317,6 @@ void testInteger() { assertSelectionQuery( "from Book where publishYear = 1995", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'publishYear': {'$eq': 1995}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } @@ -337,7 +326,6 @@ void testLong() { assertSelectionQuery( "from Book where isbn13 = 9780310904168L", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'isbn13': {'$eq': 9780310904168}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } @@ -347,7 +335,6 @@ void testDouble() { assertSelectionQuery( "from Book where discount = 0.25D", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'discount': {'$eq': 0.25}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } @@ -357,7 +344,6 @@ void testString() { assertSelectionQuery( "from Book where title = 'Holy Bible'", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'title': {'$eq': 'Holy Bible'}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } @@ -367,7 +353,6 @@ void testBigDecimal() { assertSelectionQuery( "from Book where price = 123.50BD", Book.class, - null, "{'aggregate': 'books', 'pipeline': [{'$match': {'price': {'$eq': {'$numberDecimal': '123.50'}}}}, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true}}]}", singletonList(testingBook)); } From 2745f4b2045425848768878ac67a9b3cd31b1b36 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Mon, 5 May 2025 10:07:51 -0400 Subject: [PATCH 10/13] Update src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java Co-authored-by: Viacheslav Babanin --- .../select/AbstractSelectionQueryIntegrationTests.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index b486ecae..566f482d 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -70,7 +70,11 @@ void assertSelectionQuery( .containsExactlyElementsOf(expectedResultList)); } - void assertSelectionQuery(String hql, Class resultType, String expectedMql, List expectedResultList) { + void assertSelectionQuery( + String hql, + Class resultType, + String expectedMql, + List expectedResultList) { assertSelectionQuery(hql, resultType, null, expectedMql, expectedResultList); } From 8cb0c52fc57139dd00d436269af8993479affcbe Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Mon, 5 May 2025 10:07:59 -0400 Subject: [PATCH 11/13] Update src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java Co-authored-by: Viacheslav Babanin --- .../query/select/AbstractSelectionQueryIntegrationTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index 566f482d..dc67b61b 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -98,7 +98,10 @@ void assertSelectionQuery( } void assertSelectionQuery( - String hql, Class resultType, String expectedMql, Consumer> resultListVerifier) { + String hql, + Class resultType, + String expectedMql, + Consumer> resultListVerifier) { assertSelectionQuery(hql, resultType, null, expectedMql, resultListVerifier); } From 10789b471fd14868974ad72bb8dfe25ecc471a02 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Mon, 5 May 2025 10:21:15 -0400 Subject: [PATCH 12/13] fix spotless issue; switch to package-private visibility for two access methods in AbstractSelectionQueryIntegrationTests --- .../AbstractSelectionQueryIntegrationTests.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java index dc67b61b..d5131107 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java @@ -41,11 +41,11 @@ abstract class AbstractSelectionQueryIntegrationTests implements SessionFactoryS private TestCommandListener testCommandListener; - protected SessionFactoryScope getSessionFactoryScope() { + SessionFactoryScope getSessionFactoryScope() { return sessionFactoryScope; } - protected TestCommandListener getTestCommandListener() { + TestCommandListener getTestCommandListener() { return testCommandListener; } @@ -70,11 +70,7 @@ void assertSelectionQuery( .containsExactlyElementsOf(expectedResultList)); } - void assertSelectionQuery( - String hql, - Class resultType, - String expectedMql, - List expectedResultList) { + void assertSelectionQuery(String hql, Class resultType, String expectedMql, List expectedResultList) { assertSelectionQuery(hql, resultType, null, expectedMql, expectedResultList); } @@ -98,10 +94,7 @@ void assertSelectionQuery( } void assertSelectionQuery( - String hql, - Class resultType, - String expectedMql, - Consumer> resultListVerifier) { + String hql, Class resultType, String expectedMql, Consumer> resultListVerifier) { assertSelectionQuery(hql, resultType, null, expectedMql, resultListVerifier); } From 2653a18082e0c3646e444908caee013d1e618e7c Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Mon, 5 May 2025 13:58:30 -0400 Subject: [PATCH 13/13] resolve conflict manually with latest main --- .../query/select/SimpleSelectQueryIntegrationTests.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java index cabee0e3..30dde19d 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java @@ -17,9 +17,7 @@ package com.mongodb.hibernate.query.select; import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.mongodb.hibernate.internal.FeatureNotSupportedException; import jakarta.persistence.Entity; @@ -288,11 +286,11 @@ void testNullParameterNotSupported() { @Test void testQueryPlanCacheIsSupported() { - sessionFactoryScope.inTransaction( - session -> assertThatCode(() -> session.createSelectionQuery("from Contact", Contact.class) + getSessionFactoryScope().inTransaction(session -> assertThatCode( + () -> session.createSelectionQuery("from Contact", Contact.class) .setQueryPlanCacheable(true) .getResultList()) - .doesNotThrowAnyException()); + .doesNotThrowAnyException()); } }