-->
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.  [ 4 posts ] 
Author Message
 Post subject: Indexing causing queries to be fired for non-indexed fields
PostPosted: Tue Feb 03, 2009 12:40 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2009 12:29 pm
Posts: 49
I'm using these versions of Hibernate jars.
Hibernate Core 3.3.1.GA
Hibernate Annotations 3.4.0 GA
Hibernate EntityManager 3.4.0 GA
Hibernate Search 3.1.0 GA

I'm trying to manually index an entity which has an associated entity marked with the @IndexedEmbedded annotation. Only one field in the associated entity is marked with the @Field annotation for indexing. However, when I try to manually index the main entity, it is firing select queries for all the lazy fetched fields of the associated entity. This is slowing down the indexing process. How can I prevent this from happening?

Thanks,
Seema


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 4:09 am 
Hibernate Team
Hibernate Team

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

could you provide your entity mapping and an extract of the log file showing the executed sql statements?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 5:54 am 
Beginner
Beginner

Joined: Tue Feb 03, 2009 12:29 pm
Posts: 49
hi,

Our entities are very complex, so I created some dummy ones to simulate the issue. The indexed entity is IndexedSaleEventItem which is associated with IndexedInventory which in turn is associated with IndexedPurchaseInformation. When I attempt to index the IndexedSaleEventItem, it fires a query for loading the IndexedInventory which is fine since it has an embedded index. But it also fires a query for IndexedPurchaseInformation which has no indexed fields and is marked as lazy fetched. In my actual entity, there are multiple lazy loaded fields which are causing such multiple queries to be executed making the indexing slow.

The query logs, entities and indexing code are included below.



    Hibernate: select distinct indexedsal0_.SALE_EVENT_ITEM_ID as SALE1_60_, indexedsal0_.AUCTION_TYPE as AUCTION2_60_, indexedsal0_.INVENTORY_ID as INVENTORY28_60_, indexedsal0_.ITEM_DESCRIPTION as ITEM3_60_, indexedsal0_.SALE_EVENT_ID as SALE29_60_ from ATL_SALE_EVENT_ITEM indexedsal0_

    Number of entities to be indexed 266

    indexing 0

    Hibernate: select indexedinv0_.INVENTORY_ID as INVENTORY1_59_0_, indexedinv0_.LAST_UPDATE_TIME_STAMP as LAST2_59_0_, indexedinv0_.LAST_UPDATE_USER_ID as LAST3_59_0_, indexedinv0_.REC_CRE_TIME_STAMP as REC4_59_0_, indexedinv0_.REC_CRE_USER_ID as REC5_59_0_, indexedinv0_.MAKE as MAKE59_0_ from ATL_INVENTORY indexedinv0_ where indexedinv0_.INVENTORY_ID=?

    Hibernate: select indexedpur0_.PURCHASE_INFO_ID as PURCHASE1_9_0_, indexedpur0_.LAST_UPDATE_TIME_STAMP as LAST2_9_0_, indexedpur0_.LAST_UPDATE_USER_ID as LAST3_9_0_, indexedpur0_.REC_CRE_TIME_STAMP as REC4_9_0_, indexedpur0_.REC_CRE_USER_ID as REC5_9_0_, indexedpur0_.PURCHASE_AMOUNT as PURCHASE6_9_0_, indexedpur0_.INVENTORY_ID as INVENTORY13_9_0_, indexedpur0_.PURCHASE_DATE as PURCHASE10_9_0_ from ATL_PURCHASE_INFORMATION indexedpur0_ where indexedpur0_.INVENTORY_ID=?

    indexing 1

    Hibernate: select indexedinv0_.INVENTORY_ID as INVENTORY1_59_0_, indexedinv0_.LAST_UPDATE_TIME_STAMP as LAST2_59_0_, indexedinv0_.LAST_UPDATE_USER_ID as LAST3_59_0_, indexedinv0_.REC_CRE_TIME_STAMP as REC4_59_0_, indexedinv0_.REC_CRE_USER_ID as REC5_59_0_, indexedinv0_.MAKE as MAKE59_0_ from ATL_INVENTORY indexedinv0_ where indexedinv0_.INVENTORY_ID=?

    Hibernate: select indexedpur0_.PURCHASE_INFO_ID as PURCHASE1_9_0_, indexedpur0_.LAST_UPDATE_TIME_STAMP as LAST2_9_0_, indexedpur0_.LAST_UPDATE_USER_ID as LAST3_9_0_, indexedpur0_.REC_CRE_TIME_STAMP as REC4_9_0_, indexedpur0_.REC_CRE_USER_ID as REC5_9_0_, indexedpur0_.PURCHASE_AMOUNT as PURCHASE6_9_0_, indexedpur0_.INVENTORY_ID as INVENTORY13_9_0_, indexedpur0_.PURCHASE_DATE as PURCHASE10_9_0_ from ATL_PURCHASE_INFORMATION indexedpur0_ where indexedpur0_.INVENTORY_ID=?



Code:


@Indexed
@Entity
@Table(name = "ATL_SALE_EVENT_ITEM")
public class IndexedSaleEventItem implements Serializable {

    /**
     * Comment for <code>serialVersionUID</code>.
     */
    private static final long serialVersionUID = -4745509173261900608L;

    /** The Unique Identifier. */
    @DocumentId
    @Id
    @GeneratedValue
    @Column(name = "SALE_EVENT_ITEM_ID")
    private Long id;

    /** The saleEvent.*/
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SALE_EVENT_ID")
    private SaleEvent saleEvent;

    /** The inventoryId.*/
    @IndexedEmbedded
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "INVENTORY_ID")
    private IndexedInventory inventory;

    /** The auctionType. */
    @Column(name = "AUCTION_TYPE")
    private String auctionType;

    @Field(index=Index.TOKENIZED, store=org.hibernate.search.annotations.Store.NO)
    /** The itemDescription. */
    @Column(name = "ITEM_DESCRIPTION")
    private String itemDescription;

// getters and setters

}


@Entity
@Table(name = "ATL_INVENTORY")
public class IndexedInventory extends Trackable implements Serializable {

    /** Comment for serialVersionUID. */
    private static final long serialVersionUID = -440936293775306289L;

    /** The Unique Identifier. */
    @Id
    @GeneratedValue
    @Column(name = "INVENTORY_ID")
    private Long id;

   /** The make of the Inventory. */
    @Field(index=Index.TOKENIZED, store=org.hibernate.search.annotations.Store.NO)
    @Column(name = "MAKE")
    private String make;
 
    @ContainedIn
    @OneToMany(mappedBy="inventory",  fetch = FetchType.LAZY)
    private Collection<IndexedSaleEventItem> saleEventItems;
   
    /** Purcahse Information for the item. */
    @OneToOne(fetch = FetchType.LAZY, mappedBy = "inventory")
    private IndexedPurchaseInformation purchaseInformation;

   // getters and setters
}

@Entity
@Table(name = "ATL_PURCHASE_INFORMATION")
public class IndexedPurchaseInformation extends Trackable implements Serializable {

    /**
     * Comment for <code>serialVersionUID.</code>
     */
    private static final long serialVersionUID = -6535271186496400341L;

    /** The id. */
    @Id
    @GeneratedValue
    @Column(name = "PURCHASE_INFO_ID")
    private Long id;

    /** The amount. */
    @Column(name = "PURCHASE_AMOUNT")
    private Double amount;

    /** The purchaseDate. */
    @Column(name = "PURCHASE_DATE")
    private Date purchaseDate;

    /** The inventory. */
    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "INVENTORY_ID")
    private IndexedInventory inventory;
   
    // getters and setters

}

// Indexing code

EntityManager em = getAdesaJpaTemplate().getEntityManagerFactory()
            .createEntityManager();
      FullTextEntityManager fullTextEntityManager = Search
            .getFullTextEntityManager(em);

      List entities = em
            .createQuery(
                  "select distinct saleEventItem from IndexedSaleEventItem as saleEventItem " )
            .getResultList();
      System.out.println("Number of entities to be indexed "
            + entities.size());
      long startTIme = System.currentTimeMillis();
      int i = 0;
      for (Object entity : entities) {
         System.out.println("indexing " + i++);
         fullTextEntityManager.index(entity);
         //break;
      }




Thanks,
Seema


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 7:56 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
@OneToOne(fetch = FetchType.LAZY, mappedBy = "inventory")
private IndexedPurchaseInformation purchaseInformation;


this is not going to be interpreted as "Lazy", as there is one limitation in the use of Lazy loading when the referenced object could be null.

here is a complete explanation, it is not a Search specific problem:
http://www.hibernate.org/162.html

you could change the mapping to either use "constrainted=true" if your business model can support this, or use JOIN FetchType to load the useless data in a more efficient way.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.