【问题标题】:Using QueryDSL Projections.bean for Nested Classes将 QueryDSL Projections.bean 用于嵌套类
【发布时间】:2014-01-30 02:20:17
【问题描述】:

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

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

只有当我放置一个作为主键一部分的字段时才会出现问题。

谁能帮帮我? 谢谢

【问题讨论】:

  • 您能否举一个正常工作的代码示例(例如,通过使用不属于您的主键的字段)?
  • 您能否描述一下您期望的行为?如果 Ambiente 没有 idEmpresa 属性,则无法填充它,就像异常所说的那样。

标签: querydsl


【解决方案1】:

这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-23
    • 2019-01-04
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多