如何将JPA Criteria查询映射到复合类?

时间:2019-06-05 05:48:20

标签: spring hibernate jpa hibernate-criteria criteria-api

我期望的格式结果是:

public class Authority {
    private String: id;
    private String: name;
    private String: ClientApp;

    public static class ClientApp {
        private String id;
    }
}

我不知道如何创建相应的SELECT子句。我尝试过:

Join<Authority, ClientApp> clientApp = root.join("clientapp", JoinType.LEFT);
criteria
            .select(cb.construct(Authority.class,
                    root.get(Authority_.id),
                    root.get(Authority_.name),
                    root.get(Authority_.description),
                    cb.construct(Authority.ClientApp.class,clientApp.get("id"))));

但是它引发了异常:

"org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: , near line 1, column 139 [select distinct new com.vsii.oauth2.model.response.AuthorityResponse(generatedAlias0.id, generatedAlias0.name, generatedAlias0.description, new com.vsii.oauth2.model.response.AuthorityResponse$Client(generatedAlias1.id)) from com.vsii.oauth2.entity.Authority as generatedAlias0 left join generatedAlias0.client as generatedAlias1 where 1=1 order by generatedAlias0.id desc]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: , near line 1, column 139 [select distinct new com.vsii.oauth2.model.response.AuthorityResponse(generatedAlias0.id, generatedAlias0.name, generatedAlias0.description, new com.vsii.oauth2.model.response.AuthorityResponse$Client(generatedAlias1.id)) from com.vsii.oauth2.entity.Authority as generatedAlias0 left join generatedAlias0.client as generatedAlias1 where 1=1 order by generatedAlias0.id desc]"

0 个答案:

没有答案