-->
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: FetchMode.JOIN not correctly loading lazy collections
PostPosted: Thu Nov 05, 2009 3:44 am 
Newbie

Joined: Thu Nov 05, 2009 3:20 am
Posts: 1
Hello,

I am using Hibernate search and therefore indexing need to be done.
My entity is like the following:

Ship (indexed entity)
|_ books (collection)[lazy = true]

Each book has one bookNumber.
The search need to be done on the contained collections bookNumbers. So for achieving this I used the FetchMode.JOIN to load all books for indexing. But the contained collection always load only one book. I want to achieve this in one query and thats why I am using the FetchMode.JOIN because there are millions of objects which need to be indexed. So I can't use FetchMode.SELECT because it executes the SELECT query for each book and slows the indexing process.

Here is the code:
Ship.hbm.xml
<set name="books" inverse="true" lazy="true" table="BOOKS" fetch="select" cascade="all" order-by="ID desc">
<key>
<column name="SHIP_ID" precision="10" scale="0" not-null="true" />
</key>
<one-to-many class="com.domain.Book" />
</set>

Loading lazy collection code:
public void index() {

FullTextSession fullTextSession = Search.getFullTextSession(getSession());
Transaction transaction = fullTextSession.beginTransaction();

Criteria criteria = fullTextSession.createCriteria(Ship.class).setFetchMode("books", FetchMode.JOIN);

ScrollableResults results = criteria.scroll(ScrollMode.FORWARD_ONLY);
createIndex(fullTextSession, transaction, results);
}

this code always loads one object of book. Please let me know what am i doing wrong?
Thanks.


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.