I have a class Business, a class User, and a relationship class BusinessUserLink. Here is the mapping:
Code:
@Entity
@Table(name = "business")
@Indexed(index = "business")
public class Business {
// many indexed attributes here
...
}
Code:
@Entity
@Table(name = "user")
@Indexed(index = "user")
public class User {
// few indexed attributes here
...
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "linkingUser")
private List<BusinessUserLink> businessUserLinks = new ArrayList<BusinessUserLink>(0);
}
Code:
@Entity
@Table(name="business_user_link")
public class BusinessUserLink {
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "linkedBusinessId")
private Business linkedBusiness;
// which business links to it
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "linkingUserId")
private User linkingUser;
}
Now I want to index this business-user relationship as a field of business index. (Really just the user id. For example, I'd like to search for businesses with a relationship with user 1, 3, 4, 5, ...) Based on doc I would need to add BusinessUserLink collection to the mapping of Business, annotate with @IndexEmbedded, and annotate BusinessUserLink @Indexed and its attribute linkingUser @ContainedIn. This way when a user add/delete a relationship with a business, the business index will be updated.
I am thinking whether this creates a problem because updating index of business is a heavy weight operation, and a business can have many businessUserLinks. While keeping the current hibernate map, a user usually only have less than 10 BusinessUserLink relationships. Is there a way to keep the current hibernate mapping, while only updating a single field of business index when user updates a relationship, or using some query combination to achieve the user filter on business, without updating business index at all?
Thanks in advance.