Skip to content

Collections cannot be used in dto projections [DATAJPA-1785] #2078

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

Open
spring-projects-issues opened this issue Apr 5, 2017 · 2 comments
Open
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Anthony Foulfoin opened DATAJPA-1785 and commented

Hi,

I'm facing an issue when I try to use a dto projection with a spring repository

class CarProjection {
    String name;
    List<Color> colors;

    public CarProjection (String name, List<color> colors) {
        ...
    }    
}

class Car{
    String name;

    @OneToMany(mappedBy = "car")
    List<Color> colors;
}

class Color{
     @ManyToOne
     Car car;
}

The method signature in the repository :

Slice<CarProjection> findAllBy(Pageable page);

I get an exception when I call it:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [CarProjection]. Expected arguments are: java.lang.String, Color[........]

The expected second argument in the stacktrace is a Color, while I expected a List.

If I use an interface instead of a dto, it works as expected:

interface CarProjection {
    String getName();
    List<Color> getColors();
}

But i'm facing some gson serialization problems with interface projections, maybe because of the spring proxy so I can't use this workaround


Issue Links:

  • DATAJPA-1786 Projections on collection properties are not distinct

1 votes, 3 watchers

@spring-projects-issues
Copy link
Author

Kamil commented

I think, that here is simmilar issue: https://jira.spring.io/browse/DATACMNS-969

@spring-projects-issues
Copy link
Author

Mark Paluch commented

Moved to Spring Data JPA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants