Hello,
I have problem with querying collections - maybe I will show you my code first:
Code:
@Entity
@Indexed
public class PhotoGallery implements Serializable {
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Field(store = Store.NO, index = Index.TOKENIZED)
private String galleryName;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "gallery_id")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@IndexColumn(name = "list_position")
@Fetch(value = FetchMode.SELECT)
private List<GalleryImage> galleryImages = new ArrayList<GalleryImage> ();
... more fields setters / getters
}
@Entity
@Indexed
public class GalleryImage implements Serializable {
@Id
@DocumentId
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ManyToOne
@JoinColumn (name = "gallery_id", nullable = false, updatable = false, insertable = true)
@Cascade({CascadeType.SAVE_UPDATE})
private PhotoGallery owningGallery;
@Field(index = Index.TOKENIZED, store = Store.NO)
private String imageComment;
... more fields setters / getters
}
First of all probably I can't put @IndexedEmbedded on galleryImages because it's @OneToMany, and in documentation stays: "Any @ManyToMany, @*ToOne and @Embedded attribute can be annotated with @IndexedEmbedded. The attributes of the associated class will then be added to the main entity index. In the previous example, the index will contain the following fields".
In my search I need to ask for PhotoGallery objects which have given query words in field galleryName and also in galleryImages -> imageComment.
The only idea I have for now is to put in PhotoGallery a getter which will return all the imageComment as concatenated String made after iterating all the galleryImages. I think it will be huge performance problem, but maybe there is other idea to use search in way I want?
Thx in advance for any help,
Adr