HHH-13746: Implement Load by Multiple Ids using SQL AST
composite id testing
This commit is contained in:
parent
c13bfdc338
commit
afb9f9770d
|
@ -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<EntityWithAggregateId> 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();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ public class GambitDomainModel extends AbstractDomainModelDescriptor {
|
|||
EntityWithManyToOneJoinTable.class,
|
||||
EntityWithManyToOneSelfReference.class,
|
||||
EntityWithNonIdAttributeNamedId.class,
|
||||
EntityWithAggregateId.class,
|
||||
EntityWithOneToMany.class,
|
||||
EntityWithOneToOne.class,
|
||||
EntityWithOneToOneJoinTable.class,
|
||||
|
|
Loading…
Reference in New Issue