Data does not persist in bank

0

I have a PrimeFaces3.5, JSF 2.1 and JPA 2.0 application

I'm uploading a file that does not persist in the database, but the outputs on the console are ok. I do not understand why you're not committing.

Why does not it work?

Bean code:

public class FileBean implements Serializable {

    private static final long serialVersionUID = 1L;  

    private String diretorioDestino = "c:\temp\";
    @Inject
    private EntityManager manager;
    private UploadedFile uploadedFile;

    public UploadedFile getFile() {
        return uploadedFile;
    }

    public void setFile(UploadedFile uploadedFile) {
        this.uploadedFile = uploadedFile;
    }

    public void handleFileUpload(FileUploadEvent event) throws IOException {
        this.uploadedFile = event.getFile();
    }

    @SuppressWarnings("unchecked")
    public void send() throws IOException {
        if (getFile() == null) {
            FacesUtil.addErrorMessage(FacesUtil.getMensagemI18n("escolher_arquivo"));
        } else {
            String nomeArquivo = uploadedFile.getFileName().substring(uploadedFile.getFileName().lastIndexOf("\") + 1);
            XStream ler = new XStream(new DomDriver());
            ler.alias("lista", List.class);
            ler.alias("historico", Historico.class);
            ler.alias("produto", Produto.class);
            List<Produto> listaProduto = (List<Produto>) ler.fromXML(new InputStreamReader(uploadedFile.getInputstream()));
            List<Historico> invertida = new ArrayList<Historico>();

            // Collections.reverse(invertida);
            // for (Object objeto : invertida) {
            // System.out.println(objeto);
            for (Iterator<Produto> p = listaProduto.iterator(); p.hasNext();) {
                Produto prod = p.next();
                System.out.println(prod.getCodigoProduto() == null ? "Erro" : prod.getCodigoProduto());
                System.out.println(prod.getDescricao());
                for (Iterator<Historico> h = prod.getHistoricos().iterator(); h.hasNext();) 
                {
                    Historico hist = h.next();
                    System.out.println(hist.getMesesHistoricos() == null ? "Errro" : 
                    hist.getMesesHistoricos());
                    System.out.println(hist.getQuantidade());
                    // prod.getHistoricos().add(hist);
                    invertida.add(hist);
                }
                Collections.reverse(invertida); // lista invertida para calcular
                // o alfa
                for (Historico hist : invertida) {
                    System.out.println(hist.getMesesHistoricos() == null ? "Errro" : 
                    hist.getMesesHistoricos());
                    System.out.println(hist.getQuantidade());
                }
                // prod.setFatorAmortecimentoExponencial(fatorAmortecimentoExponencial);
                manager.persist(prod);// persistir após calcular o alfa
            }
            //Upload(nomeArquivo, uploadedFile.getInputstream());
            FacesUtil.addInfoMessage(FacesUtil.getMensagemI18n("arquivo_processado") + " : " + nomeArquivo);
        }
    }
}

xhtml code:

<h:form enctype="multipart/form-data">
    <p:fileUpload id="import" value="#{fileBean.file}" mode="single" label="Enviar" 
        auto="true" fileUploadListener="#{fileBean.handleFileUpload}"
        invalidFileMessage="#{msg.somente_excel}"
        allowTypes="/(\.|\/)(xml)$/" />
    <p:commandButton id="saveBtn" value="Processar" ajax="false"action="#{fileBean.send}"></p:commandButton>
    <p:dialog widgetVar="importaDlg" id="idimportaDlg" height="200" header="Realizando Importação" width="400" modal="true"
        closable="false" draggable="false" resizable="false">
        <p:panelGrid columns="1" styleClass="semBorda">
            <h:outputText value="#{msg.aguarde}" />
            <p:graphicImage library="images" name="ajax-loading-bar.png" />
        </p:panelGrid>
    </p:dialog>
</h:form>
    
asked by anonymous 08.05.2017 / 21:23

0 answers