From f9a4efaa8f464453e37724e8583a974f61ccc7f1 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 31 Jul 2024 10:16:01 +0200 Subject: [PATCH] HHH-18445 Add test for issue --- .../RecordEmbeddedPropertyNamesTest.java | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/records/RecordEmbeddedPropertyNamesTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/records/RecordEmbeddedPropertyNamesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/records/RecordEmbeddedPropertyNamesTest.java new file mode 100644 index 0000000000..62dbf9e3b4 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/records/RecordEmbeddedPropertyNamesTest.java @@ -0,0 +1,152 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.records; + +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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Embeddable; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Marco Belladelli + */ +@DomainModel( annotatedClasses = { + RecordEmbeddedPropertyNamesTest.Fee.class, + RecordEmbeddedPropertyNamesTest.Getaway.class, + RecordEmbeddedPropertyNamesTest.Vacation.class, + RecordEmbeddedPropertyNamesTest.TestFee.class, + RecordEmbeddedPropertyNamesTest.TestGetaway.class, + RecordEmbeddedPropertyNamesTest.TestVacation.class, +} ) +@SessionFactory +@Jira( "https://hibernate.atlassian.net/browse/HHH-18445" ) +public class RecordEmbeddedPropertyNamesTest { + @Test + public void testFee(SessionFactoryScope scope) { + scope.inTransaction( session -> { + final TestFee result = session.find( TestFee.class, 1L ); + assertThat( result.getFee().issuedA() ).isFalse(); + assertThat( result.getFee().issuedB() ).isTrue(); + } ); + } + + @Test + public void testGetaway(SessionFactoryScope scope) { + scope.inTransaction( session -> { + final TestGetaway result = session.find( TestGetaway.class, 1L ); + assertThat( result.getGetaway().getawayA() ).isEqualTo( "A" ); + assertThat( result.getGetaway().getawayB() ).isEqualTo( "B" ); + } ); + } + + @Test + public void testVacation(SessionFactoryScope scope) { + scope.inTransaction( session -> { + final TestVacation result = session.find( TestVacation.class, 1L ); + assertThat( result.getVacation().amount() ).isEqualTo( 7 ); + assertThat( result.getVacation().issued() ).isTrue(); + } ); + } + + @BeforeAll + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( session -> { + session.persist( new TestFee( 1L, new Fee( true, false ) ) ); + session.persist( new TestGetaway( 1L, new Getaway( "B", "A" ) ) ); + session.persist( new TestVacation( 1L, new Vacation( true, 7 ) ) ); + } ); + } + + @AfterAll + public void tearDown(SessionFactoryScope scope) { + scope.getSessionFactory().getSchemaManager().truncateMappedObjects(); + } + + @Embeddable + public record Fee(Boolean issuedB, Boolean issuedA) { + } + + @Entity( name = "TestFee" ) + static class TestFee { + @Id + private Long id; + @Embedded + private Fee fee; + + public TestFee() { + } + + public TestFee(Long id, Fee fee) { + this.id = id; + this.fee = fee; + } + + public Fee getFee() { + return fee; + } + } + + @Embeddable + record Getaway(String getawayB, String getawayA) { + } + + @Entity( name = "TestGetaway" ) + static class TestGetaway { + @Id + private Long id; + + @Embedded + private Getaway getaway; + + public TestGetaway() { + } + + public TestGetaway(Long id, Getaway getaway) { + this.id = id; + this.getaway = getaway; + } + + public Getaway getGetaway() { + return getaway; + } + } + + @Embeddable + record Vacation(Boolean issued, Integer amount) { + } + + @Entity( name = "TestVacation" ) + static class TestVacation { + @Id + private Long id; + + @Embedded + private Vacation vacation; + + public TestVacation() { + } + + public TestVacation(Long id, Vacation vacation) { + this.id = id; + this.vacation = vacation; + } + + public Vacation getVacation() { + return vacation; + } + } +}