I have encountered a problem with VaadinSpringDataHelper.
I have a class say ExampleView in which I display ExampleDTO objects which I get from ExampleService in which I use ExampleRepository. ExampleRepository extends Example as a database entity, and in the service I map them to ExampleDTO. This results in the fact that when I try to use VaadinSpringDataHelper.fromPagingRepository, I can’t use my repository, because the objects don’t match between the grid that accepts ExampleDTO and the repo that returns Example database entity. Below is a minimal code example:
Is there any way I can use VaadinSpringDataHelper with DTO?
// ExampleRepository.java
@Repository
public interface ExampleRepository extends JpaRepository<Example, Long>{}
//ExampleService.java
@Service
@AllArgsConstructor
public class ExampleService{
private final ExampleRepository repository;
private final ExampleMapper exampleMapper;
public List<ExampleDTO> findAll(){
return this.exampleMapper.map(this.repository.findAll());
}
}
//ExampleView.java
@Route("")
public class ExampleView extends VerticalLayout{
private final ExampleRepository exampleRepository;
public ExampleView(ExampleRepository exampleRepository){
this.exampleRepository = exampleRepository;
Div div = new Div();
div.add(myGrid());
add(div);
}
private Component myGrid(){
var grid = new Grid<>(ExampleDTO.class);
grid.setColumns("aaa", "bbb", "ccc");
grid.setItems(VaadingSpringDataHelpers.fromPagingRepository(exampleRepository)); //Here i get an error
return grid;
}
}