-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18816 Error when rendering the fk-side of an association in an exists subquery #9216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
110 changes: 110 additions & 0 deletions
110
...ate-core/src/test/java/org/hibernate/orm/test/query/hql/ExistsSubqueryForeignKeyTest.java
This file contains hidden or 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,110 @@ | ||
| /* | ||
| * SPDX-License-Identifier: LGPL-2.1-or-later | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.query.hql; | ||
|
|
||
| import org.hibernate.dialect.HSQLDialect; | ||
|
|
||
| import org.hibernate.testing.orm.junit.DomainModel; | ||
| import org.hibernate.testing.orm.junit.Jira; | ||
| import org.hibernate.testing.orm.junit.SessionFactory; | ||
| import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
| import org.hibernate.testing.orm.junit.SkipForDialect; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.Tuple; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * @author Marco Belladelli | ||
| */ | ||
| @DomainModel(annotatedClasses = { | ||
| ExistsSubqueryForeignKeyTest.Person.class, | ||
| ExistsSubqueryForeignKeyTest.Document.class, | ||
| }) | ||
| @SessionFactory | ||
| @SkipForDialect(dialectClass = HSQLDialect.class, reason = "HSQLDB doesn't like the case-when selection not being in the group-by") | ||
| @Jira( "https://hibernate.atlassian.net/browse/HHH-18816" ) | ||
| public class ExistsSubqueryForeignKeyTest { | ||
| @Test | ||
| public void testWhereClause(SessionFactoryScope scope) { | ||
| scope.inTransaction( session -> { | ||
| final Long result = session.createQuery( | ||
| "select count(*) from Document d join d.owner o " | ||
| + "where exists(select p.id from Person p where p.id = o.id) group by o.id", | ||
| Long.class | ||
| ).getSingleResult(); | ||
| assertThat( result ).isEqualTo( 1L ); | ||
| } ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSelectCaseWhen(SessionFactoryScope scope) { | ||
| scope.inTransaction( session -> { | ||
| final Tuple result = session.createQuery( | ||
| "select case when exists(select p.id from Person p where p.id = o.id) then 1 else 0 end," | ||
| + "count(*) from Document d join d.owner o group by o.id", | ||
| Tuple.class | ||
| ).getSingleResult(); | ||
| assertThat( result.get( 0, Integer.class ) ).isEqualTo( 1 ); | ||
| assertThat( result.get( 1, Long.class ) ).isEqualTo( 1L ); | ||
| } ); | ||
| } | ||
|
|
||
| @BeforeAll | ||
| public void setUp(SessionFactoryScope scope) { | ||
| scope.inTransaction( session -> { | ||
| final Person person1 = new Person( 1L, "person_1" ); | ||
| session.persist( person1 ); | ||
| session.persist( new Document( 1L, "doc_1", person1 ) ); | ||
| } ); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public void tearDown(SessionFactoryScope scope) { | ||
| scope.getSessionFactory().getSchemaManager().truncateMappedObjects(); | ||
| } | ||
|
|
||
| @Entity(name = "Person") | ||
| static class Person { | ||
| @Id | ||
| private Long id; | ||
|
|
||
| private String name; | ||
|
|
||
| public Person() { | ||
| } | ||
|
|
||
| public Person(Long id, String name) { | ||
| this.id = id; | ||
| this.name = name; | ||
| } | ||
| } | ||
|
|
||
| @Entity(name = "Document") | ||
| static class Document { | ||
| @Id | ||
| private Long id; | ||
|
|
||
| private String title; | ||
|
|
||
| @ManyToOne | ||
| private Person owner; | ||
|
|
||
| public Document() { | ||
| } | ||
|
|
||
| public Document(Long id, String title, Person owner) { | ||
| this.id = id; | ||
| this.title = title; | ||
| this.owner = owner; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.