diff --git a/documentation/src/main/asciidoc/userguide/chapters/query/hql/extras/hql-distinct-entity-query-example.sql b/documentation/src/main/asciidoc/userguide/chapters/query/hql/extras/hql-distinct-entity-query-example.sql deleted file mode 100644 index 13b00ca5fa..0000000000 --- a/documentation/src/main/asciidoc/userguide/chapters/query/hql/extras/hql-distinct-entity-query-example.sql +++ /dev/null @@ -1,12 +0,0 @@ - select distinct - p.id, - b.author_id, - b.id, - b.title, - p.first_name, - p.last_name - from - person p - left join - book b - on p.id=b.author_id diff --git a/documentation/src/main/asciidoc/userguide/chapters/query/hql/extras/hql-distinct-entity-query-hint-example.sql b/documentation/src/main/asciidoc/userguide/chapters/query/hql/extras/hql-distinct-entity-query-hint-example.sql deleted file mode 100644 index 03006d1463..0000000000 --- a/documentation/src/main/asciidoc/userguide/chapters/query/hql/extras/hql-distinct-entity-query-hint-example.sql +++ /dev/null @@ -1,12 +0,0 @@ -select - p.id, - b.author_id, - b.id, - b.title, - p.first_name, - p.last_name -from - person p -left join - book b - on p.id=b.author_id \ No newline at end of file diff --git a/documentation/src/test/java/org/hibernate/userguide/hql/SelectDistinctTest.java b/documentation/src/test/java/org/hibernate/userguide/hql/SelectDistinctTest.java index 6d119ecc1a..d336c769ae 100644 --- a/documentation/src/test/java/org/hibernate/userguide/hql/SelectDistinctTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/hql/SelectDistinctTest.java @@ -8,25 +8,21 @@ package org.hibernate.userguide.hql; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; + +import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; + +import org.junit.Before; +import org.junit.Test; + import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import jakarta.persistence.Index; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import org.hibernate.jpa.QueryHints; -import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; - -import org.hibernate.transform.DistinctResultTransformer; -import org.junit.Before; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.Assert.assertTrue; @@ -82,90 +78,6 @@ public class SelectDistinctTest extends BaseEntityManagerFunctionalTestCase { }); } - @Test - public void testAllAuthors() { - - doInJPA( this::entityManagerFactory, entityManager -> { - List authors = entityManager.createQuery( - "select p " + - "from Person p " + - "left join fetch p.books", Person.class) - .getResultList(); - - authors.forEach( author -> { - log.infof( "Author %s wrote %d books", - author.getFirstName() + " " + author.getLastName(), - author.getBooks().size() - ); - } ); - }); - } - - @Test - public void testDistinctAuthors() { - - doInJPA( this::entityManagerFactory, entityManager -> { - //tag::hql-distinct-entity-query-example[] - List authors = entityManager.createQuery( - "select distinct p " + - "from Person p " + - "left join fetch p.books", Person.class) - .getResultList(); - //end::hql-distinct-entity-query-example[] - - authors.forEach( author -> { - log.infof( "Author %s wrote %d books", - author.getFirstName() + " " + author.getLastName(), - author.getBooks().size() - ); - } ); - }); - } - - @Test - public void testDistinctAuthorsWithoutPassThrough() { - - doInJPA( this::entityManagerFactory, entityManager -> { - //tag::hql-distinct-entity-query-hint-example[] - List authors = entityManager.createQuery( - "select distinct p " + - "from Person p " + - "left join fetch p.books", Person.class) - .setHint( QueryHints.HINT_PASS_DISTINCT_THROUGH, false ) - .getResultList(); - //end::hql-distinct-entity-query-hint-example[] - - authors.forEach( author -> { - log.infof( "Author %s wrote %d books", - author.getFirstName() + " " + author.getLastName(), - author.getBooks().size() - ); - } ); - }); - } - - @Test - public void testDistinctAuthorsWithResultTransformer() { - - doInHibernate( this::entityManagerFactory, session -> { - //tag::hql-distinct-entity-resulttransformer-example[] - List authors = session.createQuery( - "select p " + - "from Person p " + - "left join fetch p.books", Person.class) - .setResultListTransformer( DistinctResultTransformer.INSTANCE ) - .getResultList(); - //end::hql-distinct-entity-resulttransformer-example[] - - authors.forEach( author -> { - log.infof( "Author %s wrote %d books", - author.getFirstName() + " " + author.getLastName(), - author.getBooks().size() - ); - } ); - }); - } - @Entity(name = "Person") @Table( name = "person") public static class Person {