Using QueryDSL Projections.bean for nested classes

I use QueryDSL to map my queries to my Beans using this:

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));

My problem is that I have nested classes for primary keys, for example:

@EmbeddedId
protected AmbientePK ambientePK;

Then, when I try to execute the above code, an error occurs:

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

The problem only occurs when I put a field that is part of my primary key.

Can anybody help me? thanks

+4
source share
1 answer

Do it:

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

All Articles