Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Element {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "titleId", insertable = false, updatable = false)
@NotFound(action = NotFoundAction.IGNORE)
private TextSet titleText;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "helpId", insertable = false, updatable = false)
@NotFound(action = NotFoundAction.IGNORE)
private TextSet helpText;
}
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class TextSet extends BaseModel {
@OneToMany(mappedBy = "textSet", fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
private Set<Text> texts;
}
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Text extends BaseModel {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "textId", insertable = false, updatable = false)
private TextSet textSet;
private int language;
private String text;
}
With this setup I have an element entity which contains several textsets (two of which are shown in this example). Each textset contains a set of texts in various languages. This setup works, but it is quite slow for large datasets with lots of elements.
In my hibernate config I've added this line:
Code:
<property name="hibernate.default_batch_fetch_size">1000</property>
This setting successfully batches fetches for the most part, but not in this case. When I start to iterate over the elements and read its texts, Hibernate reads one by one textset from the database. Sometimes small batches are used, but that happens seldomly. I can see this through enabling sql logging.
Are Hibernate capable of doing batch fetches for this situation?