spring-projects / spring-projects/spring-data-jpa
Returning Converted entity properties cause DTO projection rewrite
@mp911de is already working on this.
Since Jul 3, 2025.
- Dominant language
- Java
- Stars
- 3.3k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
When a Spring Data JPA query returns a view (interface or just a single property), it is now required that converted properties provide a redundant constructor with their own class as parameter. E.g.
public interface DemoRepository extends JpaRepository<DemoEntity, Long> {
@Query("SELECT e.valueObject1 FROM DemoEntity e")
DemoValueObject1 findFirstValueObject1();
}
the DemoValueObject1 (mapped by an AttributeConverter to string) needs such a really redundant ctor:
public class DemoValueObject1 {
private String value;
public DemoValueObject1(DemoValueObject1 value) {
this.value = value.getValue();
}
}
otherwise it fails with
org.hibernate.query.SemanticException: Missing constructor for type 'DemoValueObject2' [SELECT new com.example.demo.DemoValueObject2(e.valueObject2) FROM DemoEntity e]
Here is the full minimal sample application to reproduce it:
https://github.com/hirth-abi/spring_boot_353_2/blob/main/src/test/java/com/example/demo/DemoRepositoryTest.java
Tested with Spring Boot 3.5.3, this was not required in Spring Boot 3.4.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.