Projection over embedded collection returns only the first element

Description

from the mailing list: http://lists.jboss.org/pipermail/hibernate-dev/2015-May/012775.html

For example, if I index the following entity:

@Indexed public static class ExampleEntity { @Field(store = Store.YES) Integer someInteger; ... @Field(store = Store.YES) @IndexedEmbedded List<Integer> someCollection; }

and than add a projection on "someCollection"

EntityInfo.getProjection()[0]

will only return the first result of the
collection instead of returning a List<Integer>.

Activity

Show:

Yoann RodièreOctober 16, 2019 at 6:30 AM

I'm not sure there is a solution to your problem, but there are things you can try.

You could try projecting on the entire document, then manually getting values from the projected document. For Lucene, use ProjectionConstants.DOCUMENT which will return a org.apache.lucene.Document. For Elasticsearch, use ElasticsearchProjectionConstants.SOURCE which will return the full document source as a String. Obviously, performance will degrade, but it might be acceptable for your use case.

If you really need to, you could bypass the query DSL completely and execute queries yourself. Be warned: it can get pretty complicated, especially for Lucene. For Lucene, use the index reader accessor. For Elasticsearch, use the REST client directly

Frank RiccobonoOctober 15, 2019 at 5:45 PM

Just curious - are there any user-space workarounds for this issue other than abandoning projections in favor of managed entities?

In our use-case, it would be helpful even if the projection can’t return the full array, if it could return an element that matched the query rather than always the first element.

Fixed

Details

Assignee

Reporter

Sprint

Fix versions

Priority

Created June 5, 2015 at 3:15 PM
Updated July 31, 2020 at 1:15 PM
Resolved June 10, 2020 at 8:50 AM