使用QueryDSL Projections.bean进行嵌套类

时间:2014-01-10 22:31:57

标签: querydsl

我正在使用QueryDSL将查询映射到我的Beans:

QAmbiente qitem=new QAmbiente("x");
SQLTemplates template = new MySQLTemplates(); // SQL-dialect
Configuration configuration = new Configuration(template); 
SQLQuery query = new SQLQuery(conn, configuration);
List<Ambiente> items = query.from(qitem).list(Projections.fields(Ambiente.class, qitem.idEmpresa));

我的问题是我有主键的嵌套类,如下所示:

@EmbeddedId
protected AmbientePK ambientePK;

然后,当我尝试执行上面的代码时,会抛出错误:

The bean of type: br.com.fitsoft.cnfe.model.domain.Ambiente has no property called: idEmpresa

只有当我放置一个属于我主键的字段时才会出现问题。

有人能帮帮我吗? 谢谢

1 个答案:

答案 0 :(得分:2)

这样做:

.list(Projections.bean(ItemNotaFiscal.class,
    i.aliqCofinsReal.as("aliqCofinsReal"),
    i.aliqPisPerc.as("aliqPisPerc"),
    Projections.bean(Qpk, 
            i.ambientePK.idEmpresa
    ).as("ambientePK")
));
相关问题