Follows up on [https://hibernate.atlassian.net/browse/HSEARCH-3927|https://hibernate.atlassian.net/browse/HSEARCH-3927|smart-link].
Use case: define a parameter of a projection constructor as a specific inner projection either something completely different from field projections such as an identifier projection, or more precise configuration of field value/object projections.
For example:
{code:java}@ProjectionConstructor record MyProjection(@IdProjection String id, @FieldProjection(convert = ValueConvert.NO) String myEnum){code}
Currently, all constructor parameters are bound implicitly, which limits users to field projections or object projections. There is no ID projection in particular, which prevents from fully loading an entity through its projection constructor, since it can’t project on the ID. This also means {{-parameters}} _must_ be passed to the compiler when compiling projection constructors.
Core set of annotations (must be implemented):
* {{@IdProjection}} * {{@FieldProjection}} * {{@ObjectProjection}} ** we might want a {{includeDepth}} in here, * {{@ProjectionBinding(binder = ...)}} (for custom projection annotations)
Less useful/more challenging annotations that could be split into another ticket:
* {{@ScoreProjection}} * {{@DistanceProjection}} (=> moved to [https://hibernate.atlassian.net/browse/HSEARCH-4807|https://hibernate.atlassian.net/browse/HSEARCH-4807|smart-link] ) * {{@EntityProjection}} * {{@EntityReferenceProjection}} * {{@DocumentReferenceProjection}} * Others, see all projections available.
Some things to test in particular:
* There should be no error if {{-parameters}} is not used when compiling, as long as all constructor parameters of a projection constructor have a {{@*Projection}} annotation (and that projection specifies the field path, if relevant). * There should be an error if {{-parameters}} is not used when compiling, and all constructor parameters of a projection constructor have a {{@*Projection}} annotation, but one of them is annotated with {{@FieldProjection}} or {{@ObjectProjection}} and does not specify the field path. * There should be an error when using two {{@*Projection}} annotations on the same constructor parameter. * And more (the list above is not exhaustive, obviously). |
|