Hello,
I am working on a project that uses Hibernate Search to manage Lucene indexes. One goal of my application to promote modularity, so that pieces of code can be tested independently of the rest of the application. My application has two modules: the student module and the school module. The school module has a build-time dependency on the student module, but the student module can be deployed independently of the student module. Here are my Entities:
Code:
package com.ben.student;
@Entity
public class Student {
private Integer id;
private String name;
@Id
public Integer getId() { return id; }
public void setId( Integer id ) { this.id = id; }
public String getName() { return name; }
public void setName( String name ) { this.name = name; }
}
Code:
package com.ben.school;
import com.ben.student.Student;
@Entity
public class School {
private Integer id;
private String schoolName;
private List<Student> students;
@Id
public Integer getId() { return id; }
public void setId( Integer id ) { this.id = id; }
public String getSchoolName() { return schoolName; }
public void setSchoolName( String schoolName) { this.schoolName = schoolName; }
@IndexedEmbedded
@OneToMany
public List<Student> getStudents() {
return students;
}
public void setStudents( List<Student> students ) {
this.students = students;
}
}
If I create a school called "School 12" with two students named "Bob" and "Joe", I see two entries in Student's "name" index, and two entries in School's "student.name" index, as expected: Bob and Joe. However, if I change Bob's name to Robert, only the Student's "name" index is updated (not the School's "student.name" index). This is expected behavior, from what I understand, and every article I have read tells me to put a @ContainedIn annotation in my Student class, like so:
Code:
Student.java:
....
@ContainedIn
@ManyToOne
private School school;
public School getSchool() { return school; }
public void setSchool( School school ) { this.school = school; }
However, as I mentioned earlier, I can't put a @ContainedIn annotation in my Student class, because it is built independently from the School module. Is there another way to tell Hibernate Search to update the School indexes when a student is changed?
Thanks in advance.