-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Batch fetching of sub-entities
PostPosted: Wed Sep 15, 2010 5:09 am 
Newbie

Joined: Mon Jul 12, 2010 5:41 am
Posts: 6
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.