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: