Projection in JPQL with property of type list

让人想犯罪 __ 提交于 2019-12-25 00:57:44

问题


How I can made a select of a property of type list on JPQL? example:

@Entity
public class Person {

    @id
    private Long id;
    private String name;
    private String lastname;
    private String birthdate;
    @OneToMany
    private List<Phone> getPhones();

    ...
}

@Entity
public class Phone {

    @id
    private Long id;
    private String number;

    ...
}

And on repository I want a projection, so:

public interface IPersonProjection {

    Long getId();
    String getName();
    List<Phone> phones();
}




@Repository
public interface IAtendimentoRepository extends JpaRepository<Atendimento, Long> {

    @Query("SELECT P.id, P.name, P.phones FROM Person P ")
    List<IPersonProjection> findAllProjected();
}

But when I try this (SELECT P.id, P.name, P.phones FROM Person P) occur an error on syntax of SQL.


回答1:


As specified in Spring Data Docs, you should have accessors of your properties in your Projection Interface. So i think you should change the name of phones method of IPersonProjection to getPhones.



来源:https://stackoverflow.com/questions/51558663/projection-in-jpql-with-property-of-type-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!