|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later |
| 5 | + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html |
| 6 | + */ |
| 7 | +package org.hibernate.orm.test.query; |
| 8 | + |
| 9 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 10 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 11 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 12 | +import org.junit.jupiter.api.AfterEach; |
| 13 | +import org.junit.jupiter.api.BeforeEach; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +import jakarta.persistence.Entity; |
| 17 | +import jakarta.persistence.Id; |
| 18 | + |
| 19 | +@DomainModel(annotatedClasses = { |
| 20 | + SelectJoinedAssociationMultipleTimesTest.Book.class |
| 21 | +}) |
| 22 | +@SessionFactory |
| 23 | +public class SelectJoinedAssociationMultipleTimesTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + public void test(SessionFactoryScope scope) { |
| 27 | + scope.inTransaction( |
| 28 | + session -> { |
| 29 | + // Add a proxy first to trigger the error |
| 30 | + session.getReference( Book.class, 1 ); |
| 31 | + session.createSelectionQuery( "select b b1, b b2 from Book b", Object[].class ).getResultList(); |
| 32 | + } |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + @BeforeEach |
| 37 | + public void prepareTestData(SessionFactoryScope scope) { |
| 38 | + scope.inTransaction( (session) -> session.persist( new Book( 1, "First book" ) ) ); |
| 39 | + } |
| 40 | + |
| 41 | + @AfterEach |
| 42 | + public void dropTestData(SessionFactoryScope scope) { |
| 43 | + scope.inTransaction( (session) -> session.createMutationQuery( "delete Book" ).executeUpdate() ); |
| 44 | + } |
| 45 | + |
| 46 | + @Entity( name = "Book") |
| 47 | + public static class Book { |
| 48 | + @Id |
| 49 | + private Integer id; |
| 50 | + private String name; |
| 51 | + |
| 52 | + public Book() { |
| 53 | + } |
| 54 | + |
| 55 | + public Book(Integer id, String name) { |
| 56 | + this.id = id; |
| 57 | + this.name = name; |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments