cannot be cast to java.util.Map

Asked

Viewed 813 times

5

The method below that I created in the model layer, is returning me the error "cannot be cast to java.util.Map"

public  List<NotaFiscalProduto> listaItens (boolean entSaid, Date dtinicio, Date dtfim){

    Criteria r = this.session.createCriteria(NotaFiscalProduto.class,"nfp");

    if(dtinicio != null && dtfim != null){

        r.createAlias("notafiscal", "nf");

        r.add(Restrictions.and(Restrictions.ge("nf.dataemissao", dtinicio),Restrictions.le("nf.dataemissao", dtfim)));

        r.createAlias("nf.tipomovimento", "tm");

        r.add(Restrictions.eq("tm.tiponf", entSaid));

        r.createAlias("produto", "pd");

        r.setProjection(Projections.projectionList()
                .add(Projections.property("nf.notafiscalid"), "notafiscal.notafiscalid")
                .add(Projections.property("nfp.quantidade"), "quantidade")
                .add(Projections.property("pd.produtoid"), "produto.produtoid")
                .add(Projections.property("pd.nome"), "produto.nome")
                .add(Projections.property("pd.preco"), "produto.preco"))
                .setResultTransformer(Transformers.aliasToBean(NotaFiscalProduto.class));   

        return  (List<NotaFiscalProduto>) r;
    }
  • Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!

1 answer

4

The variable r is an instance of Criteria and cannot be converted to a List. Actually to return the result list you should use the method list() as follows:

return  (List<NotaFiscalProduto>) r.list();

list()

Get the Results.

In free translation:

Get the results.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.