My classes look like (simplified)
Code:
@Indexed
@Entity
public class Relation implements Serializable { // I should have called this Person instead of Relation to avoid confusion with the word relationship
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int relationsID;
@Field(index=Index.YES, store=Store.NO)
private String name;
@IndexedEmbedded
@OneToMany(mappedBy="relation")
private Set<Address> addresses;
}
@Indexed
@Entity
public class Address implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int addressesID;
@Field(index=Index.YES, store=Store.NO)
private String address;
@Field(index=Index.YES, store=Store.NO)
private String postalCode;
@ContainedIn
@ManyToOne
@JoinColumn(name="RelationsID", nullable=false)
private Relation relation;
}
So if I'm correct I should call Address the owner of the relationship.
I'm not updating the relationship but just the postal code in the Address. The update isn't performed through hibernate but with a manual query (which is something I can't change).
I get a notification of this update by a database trigger which results in a manual update like:
Code:
fullTextSession.index(address);
The problem is that when I try to search for a Relation (Person) by the new updated postal code ('YY1234') I don't get any results. Relevant code:
Code:
...
String[] onFields = new String[]{"name", "addresses.postalCode"};
FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(qb.keyword().onFields(onFields).matching("YY1234").createQuery(), Relation.class);
List result = persistenceQuery.getResultList();
...
Things work properly if I update the complete relation object like the code below. But I would like to avoid this step. Figuring out which object to load to update the index can be very hard in a more complex domain model.
Code:
Object relation = fullTextSession.load(Relation.class, 10);
fullTextSession.index(relation);