Folks,
I'm having some trouble setting up a report containing subreport, i've done a lot of research on this problem but it wasn't solution to help solve it till this point.
The environment settings are as follows:
Java version: 1.8.0_112
Report IDE: Jasper Soft Studio version 6.3.1
Maven Library
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.3.1</version>
</dependency>
I initially tried to send a list to the report that worked normally as follows:
Java implementation processing the query in the application:
List<Monitoramento> monitoramentos = this.documentoEletronicoService.obterMonitoramentosNUD();
if(!monitoramentos.isEmpty()){
for (Monitoramento monitoramento : monitoramentos) {
monitoramento.setEventosNFE(this.documentoEletronicoService.obterEventosNFE());
}
StringBuilder jasperFile = new StringBuilder("");
jasperFile.append(JASPER_PATH);
jasperFile.append(MONITORAMENTO_JASPER_FILE);
StringBuilder jrPrintFile = new StringBuilder("");
jrPrintFile.append(JASPER_PATH);
jrPrintFile.append(MONITORAMENTO_JRPRINT_FILE);
processarRelatorioMonitoramento(monitoramentos, obterParametros(), jasperFile.toString(), jrPrintFile.toString());
}
private void processarRelatorioMonitoramento(List<Monitoramento> monitoramentos, Map<String, Object> parametros, String jasperFile, String jrPrintFile) {
StringBuilder msg = new StringBuilder("");
try {
String reportUrlReal = obterExternalContext().getRealPath(jasperFile);
String pdfFilePath = obterExternalContext().getRealPath(jrPrintFile);
JasperFillManager.fillReportToFile(reportUrlReal, parametros, new JRBeanCollectionDataSource(monitoramentos));
JasperExportManager.exportReportToPdfFile(pdfFilePath);
} catch (Exception e) {
msg.append("Erro ao gerar relarório de monitoramento ");
logger.error(msg.append(e.getMessage()));
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ""));
}
}
But when I include the subreport it's happening the following error:
Java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@285b0645
I am reporting that both Eclipse and Jasper Soft Studio are set with jdk 1.8
I decided to set up the Jasper Soft Studio connection to the DB2 database directely and the connection worked normally, brought the queries into the main report, and
the subreport. I generated the fields automatically by jasper soft studio and previewing works perfectly by displaying both the report and the sub report
with the data but when I try to run by the application is presenting the following error
Exception
ERROR: Error preparing statement for executing the report query:
SELECT
P.CPF_CNPJ CNPJ_ENTIDADE_CREDITO,
P.NOME NOME_ENTIDADE_CREDITO,
T.ID_NFE CHAVE_ACESSO,
NFEM.NUMERO_PROTOCOLO PROTOCOLO_AUTORIZACAO,
NFEM.DATA_AUTORIZACAO DATA_AUTORIZACAO,
MNFE.OBSERVACAO STATUS_ATUAL_NFE,
LPAD(R.NR_CNPJ_CEDENTE,14,0) || LPAD(R.ID_REGISTRO_UNICO,10,0) || LPAD(R.NR_CPFCNPJ_SACADO,14,0) NUD
FROM PUBLIC.TITULO T
INNER JOIN PUBLIC.PESSOA P ON (T.FK_ID_CONSULTORA = P.ID)
INNER JOIN PUBLIC.NFE_MONITORADA NFEM ON (T.ID_NFE = NFEM.CHAVE_ACESSO AND NFEM.ID = (SELECT MAX(ID) FROM PUBLIC.NFE_MONITORADA NFEM WHERE CHAVE_ACESSO = T.ID_NFE))
INNER JOIN PUBLIC.NFE_MONITORADA_MONITORAMENTO NFEMM ON (NFEM.ID = NFEMM.FK_ID_NFE_MONITORADA)
INNER JOIN PUBLIC.MONITORAMENTO_NFE MNFE ON (NFEMM.FK_ID_MONITORAMENTO = MNFE.ID)
INNER JOIN PUBLIC.REGISTRO R ON (T.FK_ID_REGISTRO_UNICO = R.ID_REGISTRO_UNICO)
WHERE T.ID = 9736334
I inform that the above query is the one executed by the main report, I modified it for a very basic query to test but anyway the error stays
Java implementation processing query within jasper soft studio
public static final String MONITORAMENTO_JASPER_FILE = "monitoramentoNUD.jasper";
public static final String MONITORAMENTO_JRPRINT_FILE = "monitoramento.jrprint";
public static final String JASPER_PATH = "\WEB-INF\classes\jasper\";
public static final String JASPER_IMG_PATH = "\WEB-INF\classes\img\logo.png";
public void obterRelatorioMonitoramento() {
StringBuilder jasperFile = new StringBuilder("");
jasperFile.append(JASPER_PATH);
jasperFile.append(MONITORAMENTO_JASPER_FILE);
StringBuilder jrPrintFile = new StringBuilder("");
jrPrintFile.append(JASPER_PATH);
jrPrintFile.append(MONITORAMENTO_JRPRINT_FILE);
processarRelatorioMonitoramento(obterParametros(), jasperFile.toString(), jrPrintFile.toString());
}
private void processarRelatorioMonitoramento(Map<String, Object> parametros, String jasperFile, String jrPrintFile) {
StringBuilder msg = new StringBuilder("");
try {
String reportUrlReal = obterExternalContext().getRealPath(jasperFile);
String pdfFilePath = obterExternalContext().getRealPath(jrPrintFile);
JasperFillManager.fillReportToFile(reportUrlReal, parametros);
JasperExportManager.exportReportToPdfFile(pdfFilePath);
} catch (Exception e) {
msg.append("Erro ao gerar relarório de monitoramento ");
logger.error(msg.append(e.getMessage()));
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ""));
}
}
private Map<String, Object> obterParametros() {
Map<String, Object> parametros = new HashMap<String, Object>();
parametros.put("logoPath", obterExternalContext().getRealPath(JASPER_IMG_PATH));
parametros.put("REPORT_CONNECTION", this.documentoEletronicoService.obterConexao());
return parametros;
}
public Connection obterConexao(){
Session session = em.unwrap(Session.class);
MyWork myWork = new MyWork();
session.doWork(myWork);
return myWork.getConnection();
}
private static class MyWork implements Work {
Connection conn;
@Override
public void execute(Connection arg0) throws SQLException {
this.conn = arg0;
}
Connection getConnection() {
return conn;
}
}
Thank you for your cooperation, any guidance would be appreciated.