3

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.