I have a multi module project where it read a byte array column from database and create a jasper file to sent it to email.
From my web application it works perfectly, but when running from my Java SE application I'm getting the following error:
Caused by: java.lang.RuntimeException: net.sf.jasperreports.engine.JRException: Error loading object from file : D:\file.jasper
at com.project.RReportJasper.gerarJasperPrint(RReportJasper.java:78)
at com.project.RReportJasper.gerarJasperPrint(RReportJasper.java:53)
at com.project.RReportJasper.geraRelatorioPDF(RReportJasper.java:29)
at com.project.RGenerate.geraRelatorio(RGenerate.java:63)
at com.project.AbstractUtil.gerar(AbstractUtil.java:44)
at com.project.util.Util.gerar(DameUtil.java:66)
at com.project.mail.EnvioEmailAbstractBase.montarAnexo(EnvioEmailAbstractBase.java:514)
... 16 more
The weird is when reading from my web application, the return of bytes from database is 120323 bytes and when the Java SE application read this, the size is 240645 (double size)
Here is my entity class:
@Entity
@Table(name= "arquivo")
public class EArquivo extends TransferObject<Long> {
private static final long serialVersionUID = -183345111110383391L;
private byte[] arquivo;
private String nome;
@Override
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "arquivo_id_seq")
@SequenceGenerator(name = "arquivo_id_seq", allocationSize = 1, sequenceName = "arquivo_id_seq")
@Column(name = "id_arquivo")
public Long getId() {
return id;
}
@Column (name = "arquivo")
public byte[] getArquivo() {
return arquivo;
}
public void setArquivo(byte[] arquivo) {
this.arquivo = arquivo;
}
@Column(length=80)
@Basic(fetch = FetchType.LAZY)
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
@Transient
public File getFile() throws NotFoundException {
File file = null;
try {
if(arquivo == null){
return null;
}
byte[] bytes = arquivo;
if (bytes.length == 0) {
throw new NotFoundException("Not found for: " + getFilial().getCnpj());
}
String cnpj = getFilial().getCnpj();
file = Arquivo.createTempFile("file-" + cnpj + "-", ".jasper");
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
fos.flush();
fos.close();
FileCleaner.track(file, file);
} catch (IOException e) {
throw new RuntimeException(e);
}
return file;
}
}
Someone have any idea of what might be this problem?
EDIT: Add how I get the file in my bean