Merge remote-tracking branch 'upstream/main' into wip/6.0_merge

This commit is contained in:
Andrea Boriero 2021-11-15 13:52:08 +01:00
commit 1b879a65f0
5 changed files with 153 additions and 1 deletions

View File

@ -0,0 +1,25 @@
package org.hibernate.orm.test.query.criteria.internal.hhh14916;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long authorId;
@Column
public String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "author", orphanRemoval = true, cascade = CascadeType.ALL)
public List<Book> books = new ArrayList<>();
}

View File

@ -0,0 +1,32 @@
package org.hibernate.orm.test.query.criteria.internal.hhh14916;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long bookId;
@Column
public String name;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "author_id", nullable = false)
public Author author;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "book", orphanRemoval = true, cascade = CascadeType.ALL)
public List<Chapter> chapters = new ArrayList<>();
}

View File

@ -0,0 +1,22 @@
package org.hibernate.orm.test.query.criteria.internal.hhh14916;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
@Entity
public class Chapter {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long chapterId;
public String name;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "book_id", nullable = false)
public Book book;
}

View File

@ -0,0 +1,73 @@
package org.hibernate.orm.test.query.criteria.internal.hhh14916;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import static org.junit.jupiter.api.Assertions.assertEquals;
@TestForIssue(jiraKey = "HHH-14916")
@Jpa(
annotatedClasses = { Author.class, Book.class, Chapter.class }
)
public class HHH14916Test {
@BeforeEach
public void before(EntityManagerFactoryScope scope) {
populateData( scope );
}
@Test
public void testJoinOnFetchNoExceptionThrow(EntityManagerFactoryScope scope) {
scope.inTransaction( entityManager -> {
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Author> query = builder.createQuery( Author.class );
final Root<Author> root = query.from( Author.class );
final ListJoin<Author, Book> authorBookJoin = (ListJoin) root.fetch( "books", JoinType.LEFT );
final ListJoin<Book, Chapter> bookChapterJoin = authorBookJoin.joinList( "chapters", JoinType.LEFT );
final Predicate finalPredicate = builder.equal( bookChapterJoin.get( "name" ), "Overview of HTTP" );
query.where( finalPredicate );
Author author = entityManager.createQuery( query ).getSingleResult();
assertEquals( "David Gourley", author.name );
assertEquals( "HTTP Definitive guide", author.books.get( 0 ).name );
assertEquals( "Overview of HTTP", author.books.get( 0 ).chapters.get( 0 ).name );
} );
}
public void populateData(EntityManagerFactoryScope scope) {
scope.inTransaction( entityManager -> {
// Insert data
Chapter chapter = new Chapter();
chapter.name = "Overview of HTTP";
Book book = new Book();
book.name = "HTTP Definitive guide";
Author author = new Author();
author.name = "David Gourley";
book.chapters.add( chapter );
author.books.add( book );
chapter.book = book;
book.author = author;
entityManager.persist( author );
} );
}
}

View File

@ -9,7 +9,7 @@ This is meant as a guide for writing test cases to be attached to bug reports in
There are a number of tenants that make up a good test case as opposed to a poor one. In fact there are a few guides for this across the web including (http://stackoverflow.com/help/mcve[MCVE]) and (http://sscce.org/[SSCCE]). These guides all assert the same ideas albeit using different terms. Given the ubiquity of StackOverflow and the fact that the MCVE guidelines were written specifically for StackOverflow, we will use those terms here as we assume most developers have seen them before:
* (M)inimal - Provide just the minimal information needed. If second level caching is irrelevant to the bug report then the test should not use second level caching. If entity inheritance is irrelevant then do not use it in the test. If your application uses Spring Data, remove Spring Data from the test.
* (C)omplete - Provide all information needed to reproduce the problem. If a bug only occurs when using bytecode enhancement, then the test should include bytecode enhancement. In other words the test should be self-contained.
* \(C)omplete - Provide all information needed to reproduce the problem. If a bug only occurs when using bytecode enhancement, then the test should include bytecode enhancement. In other words the test should be self-contained.
* (V)erifiable - The test should actually reproduce the problem being reported.