Hello,
inspired by Emmanuel's presentation at Javapolis last year, I am currently developing a Hibernate / Hibernate Search based product search app which is supposed to allow queries like this:
"participations.person.name:Miller AND participations.role.name:composer"
The query should return a list of products (like sheet music or CDs) composed by someone called Miller. Another example: query for products having someone called Brown as interpreter.
To do so, I am developing a domain model for an existing product database. It has tables for products, persons and roles as well as one participation mapping table whereat each line ties together the IDs of a product, a person and a role ("crosstable"). These 3 IDs build the composite PK of the table, too.
In the domain model, I have modeled the crosstable as a separate class called ProductParticipation. Its composite key is mapped as an embeddable class called ProductParticipationPK holding the 3 IDs.
Each product has a set of participations, each participation has exactly one person and one role. Persons and roles both have IDs, names and a few more String attributes which shall partly be searchable.
That's what I basically did so far:
Code:
@Entity
@Indexed
class Product {
...
@OneToMany(mappedBy="product")
@IndexedEmbedded
Set<ProductParticipation> participations;
...
}
@Entity
class ProductParticipation {
...
@EmbeddedId
ProductParticipationPk id;
@ManyToOne
@JoinColumn(name="ID_T", insertable=false, updatable=false)
private Product product;
@ManyToOne
@JoinColumn(name="ID_PERS", insertable=false, updatable=false)
@IndexedEmbedded
private Person person;
@ManyToOne
@JoinColumn(name="ID_ROL", insertable=false, updatable=false)
@IndexedEmbedded
private ProductParticipationRole role;
...
}
The problem is: my test query "participations.person.name:Miller" finds nothing and doesn't even complain about misspelled field names.
These are my questions:
- Is it enough to annotate the Product class with @Indexed or will I have to annotate other classes as Indexed as well?
- How should I annotate the set Product.participations? Is it OK to use @IndexedEmbedded here?
- Does it make sense to use @IndexedEmbedded or @Field annotations inside classes which are not annotated as @Indexed?
- Do I need to use the DocumentId annotation in classes which contain @Field or @IndexedEmbedded annotations, but have no @Indexed annotation?
- Using DocumentId inside ProductParticipation would need a custom TwoWayStringBridge for the composite ID class, right?
- Is it correct to use the ManyToOne associations and the JoinColumn parameters in ProductParticipation like this?
Thank you in advance!
dewoob