Hardy, unfortunately @IndexedEmbedded doesn't work very well. Unfortunate because although Hibernate Search is a beautiful project that solves a need elegantly, the core concept behind it of managing and indexing objects and their dependencies is broken in a way that is critical to our needs. Basically, in order for @IndexedEmbedded to work, you have to either save/update all of your inter-dependent entities in 1 transaction or have a very low number of entities to save/update. This issue has been open for over 7 months with no resolution:
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-513So today, if someone needs to retrieve fields of associated entities with the above condition in hibernate search, they have to make a decision. They could simply rely on hibernate search to return back the entity object because hibernate stores the Id. Then query the database for those fields. However, if there are many associated entities and/or a deep object graph, this could introduce tremendous strain and latency.
They could store those fields in a custom lucene field. Then use projections to retrieve that data. That would be easy and fast, but are they hurting normal query performance without adding great query capabilities? And the biggest problem is they have to manage the updating of the entities. If one of the dependent entities' fields changes, how does lucene get updated? Basically this is where the
idea of Hibernate Search makes so much sense...
Or instead of storing those fields in lucene, you could store it in a separate key-value store... getting the cache-like speed benefits without unnecessarily greatly expanding lucene's index. But, of course, you still have to then manage when those values get updated.