Skip to content

Commit

Permalink
Update Projection section in reference documentation.
Browse files Browse the repository at this point in the history
Closes #3216
  • Loading branch information
mp911de committed Dec 3, 2024
1 parent 36b0c26 commit 75175d6
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,29 @@ void someMethod(PersonRepository people) {
NOTE: Query parameters of type `Class` are inspected whether they qualify as dynamic projection parameter.
If the actual return type of the query equals the generic parameter type of the `Class` parameter, then the matching `Class` parameter is not available for usage within the query or SpEL expressions.
If you want to use a `Class` parameter as query argument then make sure to use a different generic parameter, for example `Class<?>`.

[NOTE]
====
When using <<projections.dtos,Class-based projection>>, types must declare a single constructor so that Spring Data can determine their input properties.
If your class defines more than one constructor, then you cannot use the type without further hints for DTO projections.
In such a case annotate the desired constructor with `@PersistenceCreator` as outlined below so that Spring Data can determine which properties to select:
[source,java]
----
public class NamesOnly {
private final String firstname;
private final String lastname;
protected NamesOnly() { }
@PersistenceCreator
public NamesOnly(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
// ...
}
----
====

0 comments on commit 75175d6

Please sign in to comment.