From e1cdad36d02630d659e4ce0fb03e274e35cc099d Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Thu, 17 May 2018 15:32:19 +0300 Subject: [PATCH] HHH-12594 - Using property "hibernate.default_batch_fetch_size" crashes bootstrapping --- .../batchfetch/BatchFetchBootstrapTest.java | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchBootstrapTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchBootstrapTest.java b/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchBootstrapTest.java new file mode 100644 index 0000000000..e02c8eb057 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchBootstrapTest.java @@ -0,0 +1,235 @@ +package org.hibernate.test.batchfetch; + +import java.sql.Blob; +import java.util.LinkedHashSet; +import java.util.Set; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.LazyToOne; +import org.hibernate.annotations.LazyToOneOption; +import org.hibernate.annotations.Polymorphism; +import org.hibernate.annotations.PolymorphismType; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +public class BatchFetchBootstrapTest extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Authority.class, JafSid.class, UserGroup.class, File.class + }; + } + + @Override + protected void configure(Configuration configuration) { + configuration.setProperty(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, "30"); + } + + @Override + protected void buildSessionFactory() { + try { + super.buildSessionFactory(); + } + catch (Exception e) { + throw new IllegalStateException( e ); + } + } + + @Test + @FailureExpected( jiraKey = "HHH-12594") + public void test() { + + } + + @Entity(name = "File") + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "non-lazy") + public static class File extends Base { + + private Blob blob; + private Base parent; + + @Column(name = "filedata", length = 1024 * 1024) + @Lob + @Basic(fetch = FetchType.LAZY) + public Blob getBlob() { + return blob; + } + + public void setBlob(Blob blob) { + this.blob = blob; + } + + @ManyToOne(fetch = FetchType.LAZY) + public Base getParent() { + return parent; + } + + public void setParent(Base parent) { + this.parent = parent; + } + } + + @MappedSuperclass + public abstract static class DatabaseEntity { + private int id; + + @Id + @GeneratedValue + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + } + + @Entity(name = "Base") + @Polymorphism(type = PolymorphismType.EXPLICIT) + @Inheritance(strategy = InheritanceType.JOINED) + public abstract static class Base extends DatabaseEntity { + + private Set files; + + @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY) + @Fetch(FetchMode.SUBSELECT) + public Set getFiles() { + return files; + } + + public void setFiles(Set files) { + this.files = files; + } + } + + @Entity(name = "Authority") + public static class Authority extends SidEntity { + private String authority; + + public String getAuthority() { + return authority; + } + + public void setAuthority(String authority) { + this.authority = authority; + } + } + + @Entity(name = "JafSid") + public static class JafSid extends Base { + + private Set groups = new LinkedHashSet<>(); + private SidEntity relatedEntity; + private String sid; + + @ManyToMany(mappedBy = "members", fetch = FetchType.EAGER) + @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) + public Set getGroups() { + return groups; + } + + public void setGroups(Set groups) { + this.groups = groups; + } + + @OneToOne(fetch = FetchType.LAZY) + @LazyToOne(LazyToOneOption.NO_PROXY) + public SidEntity getRelatedEntity() { + return relatedEntity; + } + + public void setRelatedEntity(SidEntity relatedEntity) { + this.relatedEntity = relatedEntity; + } + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + } + + @Entity(name = "SidEntity") + public static class SidEntity extends Base { + + private JafSid sid; + + @OneToOne(mappedBy = "relatedEntity", optional = false, fetch = FetchType.EAGER, orphanRemoval = true) + @Cascade(CascadeType.ALL) + public JafSid getSid() { + return sid; + } + + public void setSid(JafSid sid) { + this.sid = sid; + } + } + + @Entity(name = "User") + public static class User extends SidEntity { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + @Entity(name = "UserGroup") + public static class UserGroup extends SidEntity { + + private Set authorities = new LinkedHashSet<>(); + private Set members = new LinkedHashSet<>(); + + @ManyToMany(targetEntity = Authority.class, fetch = FetchType.LAZY) + @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) + public Set getAuthorities() { + return authorities; + } + + public void setAuthorities(Set authorities) { + this.authorities = authorities; + } + + @ManyToMany(fetch = FetchType.LAZY) + @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) + public Set getMembers() { + return members; + } + + public void setMembers(Set members) { + this.members = members; + } + } +}