HHH-16740 Add a test case to reproduce the issue
This commit is contained in:
parent
d99c7acf63
commit
c44086778a
|
@ -0,0 +1,128 @@
|
|||
package org.hibernate.orm.test.batch;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.MapsId;
|
||||
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CompositeIdAndElementCollectionBatchingTest.EntityA.class,
|
||||
CompositeIdAndElementCollectionBatchingTest.EntityB.class,
|
||||
CompositeIdAndElementCollectionBatchingTest.EmbeddableA.class,
|
||||
CompositeIdAndElementCollectionBatchingTest.EntityId.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(
|
||||
settings = @Setting(name = Environment.DEFAULT_BATCH_FETCH_SIZE, value = "2")
|
||||
)
|
||||
@JiraKey("HHH-16740")
|
||||
class CompositeIdAndElementCollectionBatchingTest {
|
||||
|
||||
private static final EntityB ENTITY_B = new EntityB( 1L );
|
||||
private static final EntityA ENTITY_A = new EntityA(
|
||||
new EntityId( "EntityA", ENTITY_B ),
|
||||
Collections.singleton( new EmbeddableA( "EmbeddableA" ) )
|
||||
);
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.persist( ENTITY_B );
|
||||
entityManager.persist( ENTITY_A );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSelect(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
EntityA a = entityManager.find( EntityA.class, ENTITY_A.id );
|
||||
assertThat( a.elementCollection ).hasSize( 1 );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name = "EntityA")
|
||||
public static class EntityA {
|
||||
@EmbeddedId
|
||||
private EntityId id;
|
||||
|
||||
@ElementCollection
|
||||
public Set<EmbeddableA> elementCollection = new HashSet<>();
|
||||
|
||||
public EntityA() {
|
||||
}
|
||||
|
||||
public EntityA(EntityId id, Set<EmbeddableA> elementCollection) {
|
||||
this.id = id;
|
||||
this.elementCollection = elementCollection;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "EntityB")
|
||||
public static class EntityB {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
public EntityB() {
|
||||
}
|
||||
|
||||
public EntityB(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
public static class EntityId implements Serializable {
|
||||
private String id1;
|
||||
@ManyToOne
|
||||
@MapsId
|
||||
private EntityB id2;
|
||||
|
||||
public EntityId() {
|
||||
}
|
||||
|
||||
public EntityId(String id1, EntityB id2) {
|
||||
this.id1 = id1;
|
||||
this.id2 = id2;
|
||||
}
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
public static class EmbeddableA {
|
||||
private String name;
|
||||
|
||||
public EmbeddableA() {
|
||||
}
|
||||
|
||||
public EmbeddableA(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue