forked from hibernate/hibernate-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into wip/6.0_merge
- Loading branch information
Showing
5 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...te-core/src/test/java/org/hibernate/orm/test/query/criteria/internal/hhh14916/Author.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<>(); | ||
} |
32 changes: 32 additions & 0 deletions
32
...nate-core/src/test/java/org/hibernate/orm/test/query/criteria/internal/hhh14916/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<>(); | ||
} |
22 changes: 22 additions & 0 deletions
22
...e-core/src/test/java/org/hibernate/orm/test/query/criteria/internal/hhh14916/Chapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
73 changes: 73 additions & 0 deletions
73
...e/src/test/java/org/hibernate/orm/test/query/criteria/internal/hhh14916/HHH14916Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters