user3183682
user3183682

Reputation: 41

Using QueryDSL Projections.bean for Nested Classes

I'm using 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, like this:

@EmbeddedId
protected AmbientePK ambientePK;

Then when i try to execute above code, an error is thrown:

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

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

Can anyone help me please? Thanks

Upvotes: 4

Views: 5144

Answers (1)

Thomas D. K. Teixeira
Thomas D. K. Teixeira

Reputation: 96

Do this:

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

Upvotes: 3

Related Questions