Hibernate search : How to index B childs of a A parent class ? How to get only B objects that contains one specific object A using lucene?
I have a problem with lucene indexation, I insert one indexed entity in a manyToMany association but lucene doesn't index as I expected.
@Entity
@Indexed
@Table(name="level")
public class Level {
...
@IndexedEmbedded
private List<Course> courses = new ArrayList<Course>();
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@JoinTable(name = "level_course", joinColumns = { @JoinColumn(name = "level_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "course_id", nullable = false, updatable = false) })
@OrderColumn(name="corder")
public List<Course> getCourses() {
return courses;
}
...
}
@Entity
@Indexed
@Table(name="course")
@FullTextFilterDef(name = "filterLevel", impl = LuceneFilterFactory.class ,cache=FilterCacheModeType.NONE)
public class Course {
...
@ContainedIn
private List<Level> levels = new ArrayList<Level>();
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="courses")
public List<Level> getLevels(开发者_如何学JAVA) {
return levels;
}
}
When I do : level.getCourses().add(myCourse1); entityManager.save(level);
myCourse1 (with ID #10 for example) will be well created and attached to level (level is parent class, Course is the child). Then instances of "Course" are well indexed but if I have a look to the indexes generated for Course I expected to find "levels.id" with value #10. But I don't find it. I need this kind of indexation because I use LuceneFilterFactory.class on Course to filter course by one level id.
Maybe my use of @ContainedIn and @IndexEmbedded annotations is not good ? Or maybe I'm completely in the wrong way to do what I need.
To simplify :
I have 2 classes A and B, with a manyToMany association between A and B. A is master on the relation. A and B are indexed. I'd like to use hibernate search for getting B objects that contains one A object in their manyToMany association. I don't want to get all B but only B objects that contains this specific A.How to do this ?
Thanks for your help
Have you tried to place the annotations consistently? Either all on the fields or all on the getters?
精彩评论