-->
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: Problem with Indexing associated entities with @IndexEmbedde
PostPosted: Mon Feb 16, 2009 3:01 pm 
Newbie

Joined: Mon Feb 16, 2009 2:41 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.1.ga
Hibernate-Search version: 3.0.0.Beta2

I have a very simple entity association but haven't been able to get it indexed with @IndexEmbedded annotation and its driving me nuts. I have followed the hibernate-search tutorial and exactly done as described in the tutorial. THe code snippet is below. Any help in solving this problem would be greatly appreciated.

Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Indexed(index = "product")
public class Product implements Serializable{

   private Long id;
   
   private Category defaultCategory;
   
   private String productName;
   
   private ProductType productType;

        .........

       @DocumentId
       @Id
   public Long getId() {
      return id;
   }

   @Field(index=Index.TOKENIZED, store=Store.NO)
   public String getProductName() {
      return productName;
   }

   @ManyToOne
   @IndexedEmbedded(depth=1)
   @JoinColumn
   @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
   public Category getDefaultCategory() {
      return defaultCategory;
   }

   @ManyToOne
   @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
   @IndexedEmbedded
   public ProductType getProductType() {
      return productType;
   }
}
}

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Indexed(index = "category")
public class Category implements Serializable {

   @DocumentId
   @Id
   public Integer getId() {
      return id;
   }

   @Index(name="catNameIdx")
   @Column(unique=false)
   @Field(index=org.hibernate.search.annotations.Index.TOKENIZED, store=Store.NO)
   public String getName() {
      return name;
   }

   @ManyToMany
   @ContainedIn
   @OrderBy("productName ASC")
   @JoinTable(
         name="ProdCategories",
         joinColumns = { @JoinColumn(name="catId")},
         inverseJoinColumns = { @JoinColumn(name="prodId")}
      )
   @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
   public List<Product> getProducts() {
      return products;
   }
}

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProductType implements Serializable {

   @Column(unique=true, nullable=false)
   @Field(index=Index.TOKENIZED, store=Store.NO)
   public String getProductTypeName() {
      return productTypeName;
   }
}

[b] Indexing code [/b]
FullTextSession fullTextSession = Search.createFullTextSession(getSession());

List<Product> products = getSession().createQuery("from Product as product").list();

for (Product product : products) {
   // Just to make sure that these are not left uninitialized
    Hibernate.initialize(product.getDefaultCategory());
    Hibernate.initialize(product.getProductType());
    fullTextSession.index(product);
}


After the indexing, when i inspect the index with Luke, only the hibernate class name, id and productName are in the product index. The fields from the associated entities Category and ProductType are not getting indexed. Any pointers into what could be the mistake is greatly appreciated.

Regards,
Dilip
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 4:14 am 
Hibernate Team
Hibernate Team

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

any reason you are using a beta version of Hibernate Search? Indexing of embedded entities was just introduced one beta version prior to the version you are using and there where some bugs in the initial cuts of the code.

Have you tried updating to 3.0.1.GA of Hibernate Search. I think for such an update you could keep your current Hibernate version, but you have to change the Lucene version.

Personally, I would even recommend to even update to the latest version of Hibernate Search. You would have to change your Hibernate and Lucene versions, but I think it would be worth the effort. So many things improved not only in Hibernate Search itself, but also in Lucene and Hibernate Core.

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