Spring data projection

139 views Asked by At

My project has entity PostEntity with couple of many-to-many relationships, the goal is to retrieve simple projection with names of PostEntity associated entities:

@Query(" select template.name as templates, resource.name as resources from TemplateEntity template, "
        + "ResourceEntity "
        + "resource "
        + " left join template.posts as tposts "
        + " left join resource.posts as rposts "
        + " where (template.workspace =:workspace and tposts.uuid =:uuid) "
        + " or( resource.workspace =:workspace and rposts.uuid =:uuid) ")
PostDependencyModel findDependencies(@Param(value = "workspace") WorkspaceEntity workspace,
        @Param(value = "uuid") String uuid);

The projection:

public interface PostDependencyModel {

    Set<String> getTemplates();

    Set<String> getResources();
}

The problem: when the query founds at least one resource and template, it returns projection, otherwise it returns null. The question: how to return empty collection this way?

0

There are 0 answers