问题
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