Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to use Java records as projections in Spring Data Redis repository #2875

Closed
sergey-morenets opened this issue Mar 19, 2024 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@sergey-morenets
Copy link

Hi

I have a domain class Book:

@Data
@RedisHash("books")
public class Book {
	
	private List<Translation> translations;
	
	@Id
	private int id;
	
	private String name;
	
	@Indexed
	private int year;
	
	@Indexed
	private int pages;
	
	@Indexed
	private double price;
	
	private Person author;
	
	@Version
	private Integer version;
}

and BookDTO as Java record:

public record BookDTO(String name) {}

Here's my repository:

public interface BookRepository 
		extends KeyValueRepository<Book, Integer> {
	
	List<BookDTO> findBy();
}

According to the latest Spring Data Redis documentation Java records are allowed as projections:

Java Records are ideal to define DTO types since they adhere to value semantics: All fields are private final and equals(…)/hashCode()/toString() methods are created automatically. Alternatively, you can use any class that defines the properties you want to project.

However when I execute findBy() method I get an error:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [model.Book] to type [projection.BookDTO]
	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:294)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:185)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:165)

Spring Boot: 3.2.3
Java: 21

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2024
@christophstrobl
Copy link
Member

You have to use the latest spring boot milestone. DTO projections are in spring-data-redis:3.3.0-M2 and have not yet been released in a GA version.

@christophstrobl christophstrobl closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2024
@christophstrobl christophstrobl added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 25, 2024
@sergey-morenets
Copy link
Author

Hi @christophstrobl

Thank you for the quick response. Why do I need to use latest Spring Boot milestone if DTO projects are declared as implemented in the latest stable version (3.2.4) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants