-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mass Indexing w/ IndexedEmbedded FetchType.EAGER
PostPosted: Thu Jul 16, 2009 10:49 am 
Newbie

Joined: Mon Jun 01, 2009 2:30 pm
Posts: 5
I'm using the following code from Hibernate Search in Action to do mass indexing:

Code:
      Criteria query = session.createCriteria(entityClass)
         .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
         .setCacheMode(CacheMode.IGNORE)
         .setFetchSize(FETCH_SIZE)
         .setFlushMode(FlushMode.MANUAL);

      ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY);

      int items = 0;
      while (scroll.next()) {
         items++;
         session.index(scroll.get(0));
         if (items % BATCH_SIZE == 0) {
            session.flushToIndexes();
            session.clear();
         }
      }


The entity in question is "Note", which has the following one-to-many association:

Code:
    @OneToMany(mappedBy="note", fetch=FetchType.EAGER)
    @IndexedEmbedded
    public Collection<NoteEntity> getEntities() {
        return this.entities;
    }


When FetchType is EAGER, the mass indexing query comes back with multiple rows per Note, up to one per NoteEntity. Instead of serialising all of the note entities into a single document in Lucene, it creates multiple documents per Note.

When I change FetchType is LAZY, everything works as expected.

Can the above code be adapted to work in this case, or should I move to using a JPA query?


Top
 Profile  
 
 Post subject: Re: Mass Indexing w/ IndexedEmbedded FetchType.EAGER
PostPosted: Fri Jul 17, 2009 6:01 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

your problem is more Hibernate Core or better Criteria query related. Any problems with Hibernate Search are just caused by your duplicate Note instances. I would have thought that specifying DISTINCT_ROOT_ENTITY should do the trick, but it does not seem to. Have you tried to write your query like this:
Code:
      Criteria query = session.createCriteria(entityClass)
         .setFetchMode("entities", FetchMode.JOIN)
         .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
         .setCacheMode(CacheMode.IGNORE)
         .setFetchSize(FETCH_SIZE)
         .setFlushMode(FlushMode.MANUAL);


If that does not help you could maybe post the full code for Note and NoteEntity. Maybe there is something else wrong with the mapping.

--Hardy


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

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.