Skip to content

Commit 15f737e

Browse files
vladmihalceagsmet
authored andcommitted
HHH-12594 - Using property "hibernate.default_batch_fetch_size" crashes bootstrapping
1 parent 93514be commit 15f737e

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
package org.hibernate.test.batchfetch;
2+
3+
import java.sql.Blob;
4+
import java.util.LinkedHashSet;
5+
import java.util.Set;
6+
import javax.persistence.Basic;
7+
import javax.persistence.Column;
8+
import javax.persistence.Entity;
9+
import javax.persistence.FetchType;
10+
import javax.persistence.GeneratedValue;
11+
import javax.persistence.Id;
12+
import javax.persistence.Inheritance;
13+
import javax.persistence.InheritanceType;
14+
import javax.persistence.Lob;
15+
import javax.persistence.ManyToMany;
16+
import javax.persistence.ManyToOne;
17+
import javax.persistence.MappedSuperclass;
18+
import javax.persistence.OneToMany;
19+
import javax.persistence.OneToOne;
20+
21+
import org.hibernate.annotations.Cache;
22+
import org.hibernate.annotations.CacheConcurrencyStrategy;
23+
import org.hibernate.annotations.Cascade;
24+
import org.hibernate.annotations.CascadeType;
25+
import org.hibernate.annotations.Fetch;
26+
import org.hibernate.annotations.FetchMode;
27+
import org.hibernate.annotations.LazyToOne;
28+
import org.hibernate.annotations.LazyToOneOption;
29+
import org.hibernate.annotations.Polymorphism;
30+
import org.hibernate.annotations.PolymorphismType;
31+
import org.hibernate.cfg.AvailableSettings;
32+
import org.hibernate.cfg.Configuration;
33+
34+
import org.hibernate.testing.FailureExpected;
35+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
36+
import org.junit.Test;
37+
38+
public class BatchFetchBootstrapTest extends BaseCoreFunctionalTestCase {
39+
40+
@Override
41+
protected Class<?>[] getAnnotatedClasses() {
42+
return new Class[] {
43+
Authority.class, JafSid.class, UserGroup.class, File.class
44+
};
45+
}
46+
47+
@Override
48+
protected void configure(Configuration configuration) {
49+
configuration.setProperty(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, "30");
50+
}
51+
52+
@Override
53+
protected void buildSessionFactory() {
54+
try {
55+
super.buildSessionFactory();
56+
}
57+
catch (Exception e) {
58+
throw new IllegalStateException( e );
59+
}
60+
}
61+
62+
@Test
63+
@FailureExpected( jiraKey = "HHH-12594")
64+
public void test() {
65+
66+
}
67+
68+
@Entity(name = "File")
69+
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "non-lazy")
70+
public static class File extends Base {
71+
72+
private Blob blob;
73+
private Base parent;
74+
75+
@Column(name = "filedata", length = 1024 * 1024)
76+
@Lob
77+
@Basic(fetch = FetchType.LAZY)
78+
public Blob getBlob() {
79+
return blob;
80+
}
81+
82+
public void setBlob(Blob blob) {
83+
this.blob = blob;
84+
}
85+
86+
@ManyToOne(fetch = FetchType.LAZY)
87+
public Base getParent() {
88+
return parent;
89+
}
90+
91+
public void setParent(Base parent) {
92+
this.parent = parent;
93+
}
94+
}
95+
96+
@MappedSuperclass
97+
public abstract static class DatabaseEntity {
98+
private int id;
99+
100+
@Id
101+
@GeneratedValue
102+
public int getId() {
103+
return id;
104+
}
105+
106+
public void setId(int id) {
107+
this.id = id;
108+
}
109+
110+
}
111+
112+
@Entity(name = "Base")
113+
@Polymorphism(type = PolymorphismType.EXPLICIT)
114+
@Inheritance(strategy = InheritanceType.JOINED)
115+
public abstract static class Base extends DatabaseEntity {
116+
117+
private Set<File> files;
118+
119+
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
120+
@Fetch(FetchMode.SUBSELECT)
121+
public Set<File> getFiles() {
122+
return files;
123+
}
124+
125+
public void setFiles(Set<File> files) {
126+
this.files = files;
127+
}
128+
}
129+
130+
@Entity(name = "Authority")
131+
public static class Authority extends SidEntity {
132+
private String authority;
133+
134+
public String getAuthority() {
135+
return authority;
136+
}
137+
138+
public void setAuthority(String authority) {
139+
this.authority = authority;
140+
}
141+
}
142+
143+
@Entity(name = "JafSid")
144+
public static class JafSid extends Base {
145+
146+
private Set<UserGroup> groups = new LinkedHashSet<>();
147+
private SidEntity relatedEntity;
148+
private String sid;
149+
150+
@ManyToMany(mappedBy = "members", fetch = FetchType.EAGER)
151+
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
152+
public Set<UserGroup> getGroups() {
153+
return groups;
154+
}
155+
156+
public void setGroups(Set<UserGroup> groups) {
157+
this.groups = groups;
158+
}
159+
160+
@OneToOne(fetch = FetchType.LAZY)
161+
@LazyToOne(LazyToOneOption.NO_PROXY)
162+
public SidEntity getRelatedEntity() {
163+
return relatedEntity;
164+
}
165+
166+
public void setRelatedEntity(SidEntity relatedEntity) {
167+
this.relatedEntity = relatedEntity;
168+
}
169+
170+
public String getSid() {
171+
return sid;
172+
}
173+
174+
public void setSid(String sid) {
175+
this.sid = sid;
176+
}
177+
}
178+
179+
@Entity(name = "SidEntity")
180+
public static class SidEntity extends Base {
181+
182+
private JafSid sid;
183+
184+
@OneToOne(mappedBy = "relatedEntity", optional = false, fetch = FetchType.EAGER, orphanRemoval = true)
185+
@Cascade(CascadeType.ALL)
186+
public JafSid getSid() {
187+
return sid;
188+
}
189+
190+
public void setSid(JafSid sid) {
191+
this.sid = sid;
192+
}
193+
}
194+
195+
@Entity(name = "User")
196+
public static class User extends SidEntity {
197+
198+
private String name;
199+
200+
public String getName() {
201+
return name;
202+
}
203+
204+
public void setName(String name) {
205+
this.name = name;
206+
}
207+
}
208+
209+
@Entity(name = "UserGroup")
210+
public static class UserGroup extends SidEntity {
211+
212+
private Set<Authority> authorities = new LinkedHashSet<>();
213+
private Set<JafSid> members = new LinkedHashSet<>();
214+
215+
@ManyToMany(targetEntity = Authority.class, fetch = FetchType.LAZY)
216+
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
217+
public Set<Authority> getAuthorities() {
218+
return authorities;
219+
}
220+
221+
public void setAuthorities(Set<Authority> authorities) {
222+
this.authorities = authorities;
223+
}
224+
225+
@ManyToMany(fetch = FetchType.LAZY)
226+
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
227+
public Set<JafSid> getMembers() {
228+
return members;
229+
}
230+
231+
public void setMembers(Set<JafSid> members) {
232+
this.members = members;
233+
}
234+
}
235+
}

0 commit comments

Comments
 (0)