From afb9f9770ddc332c2082dadf472e9ee408455959 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 26 Nov 2019 15:12:54 -0600 Subject: [PATCH] HHH-13746: Implement Load by Multiple Ids using SQL AST composite id testing --- .../multiLoad/MultiIdEntityLoadTests.java | 34 +++++++- .../domain/gambit/EntityWithAggregateId.java | 78 +++++++++++++++++++ .../orm/domain/gambit/GambitDomainModel.java | 1 + 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/EntityWithAggregateId.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/MultiIdEntityLoadTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/MultiIdEntityLoadTests.java index d61a54dbce..3149de303d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/MultiIdEntityLoadTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/loading/multiLoad/MultiIdEntityLoadTests.java @@ -11,6 +11,7 @@ import java.util.List; import org.hibernate.testing.orm.domain.StandardDomainModel; import org.hibernate.testing.orm.domain.gambit.BasicEntity; +import org.hibernate.testing.orm.domain.gambit.EntityWithAggregateId; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryFunctionalTesting; @@ -153,6 +154,20 @@ public class MultiIdEntityLoadTests { ); } + @Test + public void testMultiLoadingCompositeId(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final List entities = session.byMultipleIds( EntityWithAggregateId.class ).multiLoad( + new EntityWithAggregateId.Key( "abc", "def" ), + new EntityWithAggregateId.Key( "123", "456" ) + ); + + assertThat( entities.size(), is( 2 ) ); + } + ); + } + @BeforeEach public void prepareTestData(SessionFactoryScope scope) { scope.inTransaction( @@ -163,6 +178,20 @@ public class MultiIdEntityLoadTests { session.save( first ); session.save( second ); session.save( third ); + + session.save( + new EntityWithAggregateId( + new EntityWithAggregateId.Key( "abc", "def"), + "ghi" + ) + ); + + session.save( + new EntityWithAggregateId( + new EntityWithAggregateId.Key( "123", "456"), + "789" + ) + ); } ); } @@ -170,7 +199,10 @@ public class MultiIdEntityLoadTests { @AfterEach public void dropTestData(SessionFactoryScope scope) { scope.inTransaction( - session -> session.createQuery( "delete BasicEntity" ).executeUpdate() + session -> { + session.createQuery( "delete BasicEntity" ).executeUpdate(); + session.createQuery( "delete EntityWithAggregateId" ).executeUpdate(); + } ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/EntityWithAggregateId.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/EntityWithAggregateId.java new file mode 100644 index 0000000000..20e31f6a03 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/EntityWithAggregateId.java @@ -0,0 +1,78 @@ +/* + * 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.testing.orm.domain.gambit; + +import java.io.Serializable; +import javax.persistence.Embeddable; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; + +/** + * @author Steve Ebersole + */ +@Entity +public class EntityWithAggregateId { + private Key key; + private String data; + + public EntityWithAggregateId() { + } + + public EntityWithAggregateId(Key key, String data) { + this.key = key; + this.data = data; + } + + @EmbeddedId + public Key getKey() { + return key; + } + + public void setKey(Key key) { + this.key = key; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + + @Embeddable + public static class Key implements Serializable { + private String value1; + private String value2; + + public Key() { + } + + public Key(String value1, String value2) { + this.value1 = value1; + this.value2 = value2; + } + + public String getValue1() { + return value1; + } + + public void setValue1(String value1) { + this.value1 = value1; + } + + public String getValue2() { + return value2; + } + + public void setValue2(String value2) { + this.value2 = value2; + } + } + +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/GambitDomainModel.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/GambitDomainModel.java index de575d628c..f9a2354050 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/GambitDomainModel.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/domain/gambit/GambitDomainModel.java @@ -30,6 +30,7 @@ public class GambitDomainModel extends AbstractDomainModelDescriptor { EntityWithManyToOneJoinTable.class, EntityWithManyToOneSelfReference.class, EntityWithNonIdAttributeNamedId.class, + EntityWithAggregateId.class, EntityWithOneToMany.class, EntityWithOneToOne.class, EntityWithOneToOneJoinTable.class,