Skip to content

Spring Data view properties require redundant constructor since Spring Boot 3.5 #46251

Closed as not planned
@hirth-abi

Description

@hirth-abi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions