You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As shown in the figure, it is mentioned in the official document that Class-based Projections cannot be used with native query, while native query is described as setting the nativeQuery flag to true.
However, when I mixed @query with Class-based Projections, I saw an error org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type.
Here is my code:
publicinterfacePersonRepositoryextendsRepository<Person, Long> {
@Query("select p from Person p where p.firstName = ?1")
PersonDtofindByFirstName(StringfirstName);
}
@EntitypublicclassPerson {
@IdprivateLongid;
privateStringfirstName;
privateStringlastName;
@OneToOne(mappedBy = "person")
privateAddressaddress;
// getter and setter ...
}
publicclassPersonDto {
privatefinalStringfirstName;
privatefinalStringlastName;
publicPersonDto(StringfirstName, StringlastName) {
this.firstName = firstName;
this.lastName = lastName;
}
publicStringgetFirstName() {
returnfirstName;
}
publicStringgetLastName() {
returnlastName;
}
@Overridepublicbooleanequals(Objecto) {
if (this == o) returntrue;
if (o == null || getClass() != o.getClass()) returnfalse;
PersonDtopersonDto = (PersonDto) o;
returnObjects.equals(firstName, personDto.firstName) && Objects.equals(lastName, personDto.lastName);
}
@OverridepublicinthashCode() {
returnObjects.hash(firstName, lastName);
}
}
The text was updated successfully, but these errors were encountered:
I understand that the reference documentation implied the code you wrote should work just fine. I updated them to clarify exactly how class-based DTOs work with Spring Data JPA, hopefully giving you the ability to leverage you PersonDto within an @Query annotation!
As shown in the figure, it is mentioned in the official document that
Class-based Projections
cannot be used with native query, while native query is described assetting the nativeQuery flag to true
.However, when I mixed
@query
withClass-based Projections
, I saw an errororg.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type
.Here is my code:
The text was updated successfully, but these errors were encountered: