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.
|