Skip to content

Commit 9a16062

Browse files
Update Projection section in reference documentation.
For the time being we at least now document the current behaviour and how to cope with it. See: #3286
1 parent cde6bf7 commit 9a16062

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

+25
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,28 @@
44
include::{commons}@data-commons::page$repositories/projections.adoc[leveloffset=+1]
55

66
NOTE: It is important to note that <<projections.dtos,Class-based projections>> with JPQL is limited to *constructor expressions* in your JPQL expression, e.g. `SELECT new com.example.NamesOnly(u.firstname, u.lastname) from User u`. (Note the usage of a FQDN for the DTO type!) This JPQL expression can be used in `@Query` annotations as well where you define any named queries. And it's important to point out that class-based projections do not work with native queries AT ALL. As a workaround you may use named queries with `ResultSetMapping` or the Hibernate specific https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/transform/ResultTransformer.html[`ResultTransformer`]
7+
8+
[NOTE]
9+
====
10+
Some JPA providers may require additional hints when working with <<projections.dtos,Class-based projections>> especially when using those directly with method derived queries.
11+
If you are facing errors like `JpaSystemException: Specified result type did not match Query selection type` make sure to provide a constructor hint via `@PersistenceCreator` to be passed on, as outlined below:
12+
13+
[source,java]
14+
----
15+
public class NamesOnly {
16+
17+
private final String firstname;
18+
private final String lastname;
19+
20+
protected NamesOnly() { }
21+
22+
@PersistenceCreator
23+
public NamesOnly(String firstname, String lastname) {
24+
this.firstname = firstname;
25+
this.lastname = lastname;
26+
}
27+
28+
// ...
29+
}
30+
----
31+
====

0 commit comments

Comments
 (0)