this is a similar question of: this issue
I tried to use the same solution, but I have this error:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: from near line 1, column 9 [select from com.app.company.domain.organization.Organization as generatedAlias0 where generatedAlias0.deletedAt is null]
Look at the select
statement: there is not any field requested!
Any idea?
Query in the Repository:
<T extends JPAProjection > List<T> findAllByDeletedAtIsNull(Class<? extends JPAProjection> projection);
Next, blank interface JPAProjection
, and OrgId
projection interface used to retrieve only id
and name
:
public interface JPAProjection {}
public interface OrgId extends JPAProjection {
@Value("#{target.id}")
Long getId();
@Value("#{target.name}")
String getName();
}
And then, the call to the query:
return organizationRepository.findAllByDeletedAtIsNull(OrgId.class);
Thanks a lot, Andrea