从数据库创建Jasper文件时出错

时间:2012-10-25 19:05:51

标签: java jasper-reports

我有一个多模块项目,它从数据库中读取一个字节数组列并创建一个jasper文件以将其发送到电子邮件。

从我的Web应用程序可以很好地工作,但是当从我的Java SE应用程序运行时,我收到以下错误:

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

奇怪的是,从我的Web应用程序读取时,数据库中的字节返回为 120323 字节,当Java SE应用程序读取此字符时,大小为 240645 (双倍大小)

这是我的实体类:

@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;
    }
}

有人知道这个问题可能是什么?

编辑:添加我在bean中获取文件的方式

1 个答案:

答案 0 :(得分:1)

问题是Postgres jar。

在我的Web容器中,版本为9.1,在我的Java SE应用程序中为8.4。 当我更新我的应用程序以使用9.1时,问题就解决了。