Remove not used examples from documentation
This commit is contained in:
parent
a9c6caa888
commit
f5fdb653a8
|
@ -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
|
|
|
@ -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
|
|
|
@ -8,25 +8,21 @@ package org.hibernate.userguide.hql;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.CascadeType;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Index;
|
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.Table;
|
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.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -82,90 +78,6 @@ public class SelectDistinctTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAllAuthors() {
|
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
|
||||||
List<Person> 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<Person> 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<Person> 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<Person> 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")
|
@Entity(name = "Person") @Table( name = "person")
|
||||||
public static class Person {
|
public static class Person {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue