Skip to content

Commit 5bbc24f

Browse files
committed
Update Projection section in reference documentation.
Closes #3216
1 parent b4edacb commit 5bbc24f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/antora/modules/ROOT/pages/repositories/projections-class.adoc

+26
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,29 @@ void someMethod(PersonRepository people) {
5757
NOTE: Query parameters of type `Class` are inspected whether they qualify as dynamic projection parameter.
5858
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.
5959
If you want to use a `Class` parameter as query argument then make sure to use a different generic parameter, for example `Class<?>`.
60+
61+
[NOTE]
62+
====
63+
When using <<projections.dtos,Class-based projection>>, types must declare a single constructor so that Spring Data can determine their input properties.
64+
If your class defines more than one constructor, then you cannot use the type without further hints for DTO projections.
65+
In such a case annotate the desired constructor with `@PersistenceCreator` as outlined below so that Spring Data can determine which properties to select:
66+
67+
[source,java]
68+
----
69+
public class NamesOnly {
70+
71+
private final String firstname;
72+
private final String lastname;
73+
74+
protected NamesOnly() { }
75+
76+
@PersistenceCreator
77+
public NamesOnly(String firstname, String lastname) {
78+
this.firstname = firstname;
79+
this.lastname = lastname;
80+
}
81+
82+
// ...
83+
}
84+
----
85+
====

0 commit comments

Comments
 (0)