Often times we just need to store the id for a related entity.
@IndexedEmbedded(includePaths={"id"}) is useful for this. However, when the owning entity is updated, HSearch has to reread this information from the database and initializes the entity.
In these situations it could make a lot of sense to use a projection query in stead of an entity initialization, especially if the number of entities is large.
If a second level cache is used, the id information could even be directly retrieved from the cache without initialization of the entities, assuming the collection is not dirty.
Projection on other than just the id is a related use case with additional complexities. In light of the idea that their might be other use cases than just the id, it could be considered to use something like this as an annotation.
@IndexedEmbedded(
optimize=Optimize.STANDARD
)
Optimize.DEFAULT - initialize the entity
Optimize.ID - optimize for id retrieval from secondary cache or id projection
Optimize.PROJECTION - optimize for projection against an arbitrary number of projected attributes (to be described elsewhere)
|