Error generating report with more than one relationship - Demoiselle Report

Asked

Viewed 153 times

1

Hello folks I’m trying to generate a report with the report Demoiselle, and I’m not managing to generate a report when I have more than one relationship, when I report from a single table is working perfectly, only does not work when it is related in more than one table, that would be so:

My query of the report:

SELECT
     DesignacaoRotineira."anoReferencia" AS anoReferencia,
     DesignacaoRotineira."tx_assunto" AS assunto,
     DesignacaoRotineira."tx_codigoDesignacao" AS codigoDesignacao,
     DesignacaoRotineira."dataEmissao" AS dataEmissao,
     DesignacaoRotineira."mesReferencia" AS mesReferencia,
     Lotacao."tx_codigoLotacao" AS codigoLotacao,
     Lotacao."tx_NomeLotacao" AS nomeLotacao
FROM
     "dbo"."Lotacao" Lotacao INNER JOIN "dbo"."DesignacaoRotineira" DesignacaoRotineira ON Lotacao."id_Lotacao" = DesignacaoRotineira."fk_lotacao_id"
WHERE
     DesignacaoRotineira."id_designacao" = $P{id}

How do I solve this problem? I took care to leave aliases according to class attributes.

The exception that occurs is the following:

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : codigoLotacao

java.lang.NoSuchMethodException: Unknown property 'codigoLotacao' on class 'class br.gov.ro.portovelho.semfaz.sisfiscal.domain.DesignacaoRotineira'

Method generating the report:

@Inject
    @Path("reports/designcaoRotineira.jasper")
    private Report relatorioPorDesignacao;

    public StreamedContent getArquivoRelatorioPorDesignacao(Long id){

        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("id",id);
        Collection<DesignacaoRotineira> dadosRelatorio = getResultList();

        try {
            byte[] buffer = relatorioPorDesignacao.export(dadosRelatorio,param,Type.PDF);
            ByteArrayInputStream bis = new ByteArrayInputStream(buffer);
            return new DefaultStreamedContent(bis, "application/pdf","designacaoRotineira.pdf");
        } catch (RuntimeException e) {
            e.printStackTrace();
            context.addMessage( null,new FacesMessage(e.getMessage()));
        }
        return null;
    }

Class Parent Designation

@Entity
public class DesignacaoRotineira extends Designacao  {

    private static final long serialVersionUID = 1L;

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
    private GrupoTrabalho grupoTrabalho;

    public DesignacaoRotineira() {

    }

    public DesignacaoRotineira(GrupoTrabalho grupoTrabalho) {
        super();
        this.grupoTrabalho = grupoTrabalho;
    }


    public GrupoTrabalho getGrupoTrabalho() {
        return grupoTrabalho;
    }

    public void setGrupoTrabalho(GrupoTrabalho grupoTrabalho) {
        this.grupoTrabalho = grupoTrabalho;
    }
}

Class Daughter Designacaorotineira:

//import ...

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Designacao implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    @Column(name = "id_designacao")
    private Long id;

    @Column(name = "tx_codigoDesignacao", unique = true, nullable = false)



    private String codigoDesignacao;

    @Column(name = "tx_assunto")
    private String assunto;

    @Temporal(TemporalType.TIMESTAMP)
    private Date dataEmissao = new Date();

    @Enumerated(EnumType.STRING)
    private EnumSituacaoDesignacao enumSituacaoDesignacao = EnumSituacaoDesignacao.ABERTA;


    private int mesReferencia = new GregorianCalendar().get(Calendar.MONTH) + 1;

    private Integer anoReferencia = new GregorianCalendar().get(Calendar.YEAR);

    @OneToOne
    @JoinColumn(name = "fk_lotacao_id")
    private Lotacao lotacao;

    @OneToMany(mappedBy = "designacao",cascade = {CascadeType.REMOVE})
    private List<LancamentoServicoDesignacao> lancamentosServicoDesignacao;

    public Designacao() {

    }



    public Designacao(String codigoDesignacao, String assunto, Date dataEmissao) {
        super();
        this.codigoDesignacao = codigoDesignacao;
        this.assunto = assunto;
        this.dataEmissao = dataEmissao;

    }

    public Designacao(String codigoDesignacao, String assunto,
            Date dataEmissao, Lotacao lotacao,
            EnumSituacaoDesignacao enumSituacaoDesignacao, int mesReferencia,
            int anoReferencia,List<LancamentoServicoDesignacao> lancamentosServicoDesignacao) {
        super();
        this.codigoDesignacao = codigoDesignacao;
        this.assunto = assunto;
        this.dataEmissao = dataEmissao;
        this.enumSituacaoDesignacao = enumSituacaoDesignacao;
        this.lotacao = lotacao;
        this.mesReferencia = mesReferencia;
        this.anoReferencia = anoReferencia;
        this.lancamentosServicoDesignacao = lancamentosServicoDesignacao;
    }

    public String getCodigoDesignacao() {
        return codigoDesignacao;
    }

    public void setCodigoDesignacao(String codigoDesignacao) {

        this.codigoDesignacao = codigoDesignacao.length() > codigoDesignacao
                .length() ? codigoDesignacao : codigoDesignacao + "."
                + lotacao.getSecretaria().getCodigoSecretaria() + "" + "."
                + lotacao.getCodigoLotacao() + "" + "." + this.mesReferencia
                + "" + "/" + anoReferencia;
    }


    //getandsetters...
}

Class Capacity:

package br.gov.ro.portovelho.semfaz.sisfiscal.domain;

//import...

@Entity
public class Lotacao implements Serializable {


    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_Lotacao")
    private Long id;

    @Column(name = "tx_NomeLotacao")
    private String nomeLotacao;

    @Column(name = "tx_codigoLotacao")
    private String codigoLotacao;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "id_secretaria_fk",nullable=false)
    private Secretaria secretaria;

    @OneToOne
    @JoinColumn(name = "id_tipoFiscalizacao_fk")
    private TipoFiscalizacao tipoFiscalizacao;

    public Lotacao() {

    }

    public Lotacao(Secretaria secretaria) {
        super();
        this.secretaria = secretaria;
    }


    public Lotacao(String nomeLotacao, Secretaria secretaria, TipoFiscalizacao tipoFiscalizacao) {
        super();
        this.tipoFiscalizacao = tipoFiscalizacao;
        this.nomeLotacao = nomeLotacao;
        this.secretaria = secretaria;
    }




    // getter and setters omitidos e hash and equals

}
  • 1

    you are trying to access the attribute 'codigoLotacao' in the entity Designacaorotineira, which obviously does not have this attribute. Use 'lotacao.codigoLotacao' instead of 'codigoLotacao'.

  • RESOLVED, in the field Fields of the Report Inspector of Ireport has to rename the field, in my case the field codeLotation for.codigoLotacao, in the report sql I left "The codigoLotacao".

No answers

Browser other questions tagged

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