tunderwood
tunderwood

Reputation: 109

Hibernate Search not indexing embedded collections properly

I'm currently working on a project that involves the use of Hibernate Search. Currently the project uses pure SQL for its searches and we would like to use a text search instead (Needing to know and correctly spell the first word can get annoying).

The schema is that a product can have multiple versions and the current version contains the name of the product.

Public Class Product extends ProgEntity
{
   private List<ProductVersion> versions = new ArrayList<ProductVersion>();
   ...
}

Public Class ProductVersion extends ProgEntity
{
    String productName;
    ...
}

I need to be able to search for a product based on its name. I was able to index the ProductVersions by productName with little issue however indexing Product is proving to be more of an issue.

After some research this is what I have however when I update the product to the DB no index is created.

@Entity
@Indexed
Public Class Product extends ProgEntity
{
   @IndexedEmbedded
   private List<ProductVersion> versions = new ArrayList<ProductVersion>();
   ...
}

@Entity
@Embeddable
Public Class ProductVersion extends ProgEntity
{
    @Field
    String productName;
    ...
}

The DocumentID is part of ProgEntity. I need to be sure that if I update Product or Product Version that it will be indexed properly which does not seem to be happening now.

Any suggestions on what I am doing incorrectly?

Upvotes: 3

Views: 1936

Answers (2)

Peter Bratton
Peter Bratton

Reputation: 6408

You don't have a relationship (eg many-to-one, many-to-one) between Product and ProductVersion mapped in the code you posted. This relationship must be bi-directional. Annotate the Product's collection field with @IndexedEmbedded, and the inverse field on the ProductVersion side with @ContainedIn, and you should be all set.

Upvotes: 1

Hardy
Hardy

Reputation: 19109

Using @Entity and @Embeddable on ProductVersion seems wrong. There are also some JPA annotations missing. Is the version collection mapped as @ManyToOne or @ElementCollection. Have you checked your hibernate configuration and log files? Which directory provider are you using?

Upvotes: 0

Related Questions