Oracle and Seam Transaction problem
I have a procedure that change the values from an object and after i have called the procedure i do a search to find the changed object but it still with the same value, instead of the value is already changed in database.
My controller receive the values to change:
@Begin(join=true, flushMode=FlushModeType.COMMIT)
public String validarArquivo() throws Exception
{
if(arquivoImportacaoId != null)
{开发者_如何学运维
importarArquivoTransacaoBusiness.validarArquivo(arquivoImportacaoId, seamSession.getIdUsuario());
arquivoImportacaoId = null;
}
//buscarArquivosImportacao();
statusValidaArquivo = 1;
return "sucesso";
}
DAO:
em.createNativeQuery("{call PRC_PROCESSAR_ARQUIVO (" + arquivoImportacaoId + ", " + UsuarioId + ") }").executeUpdate();
em.flush();
em.joinTransaction();
after the dao execution this methos is called:
@In(create = true)
EntityManager em;
public List<ArquivoImportacao> buscarArquivoTransacao(ImportarArquivoTransacaoForm importarArquivoTransacaoForm) throws Exception{
em.flush();
em.joinTransaction();
List<ArquivoImportacao> lstArquivoImportacao = new ArrayList<ArquivoImportacao>();
StringBuilder strQuery = new StringBuilder();
strQuery.append("select a from ArquivoImportacao a where 1=1 ");
strQuery.append("and a.status <> 'CAN' ");
if(importarArquivoTransacaoForm != null)
{
if (importarArquivoTransacaoForm.getIdArquivo() != null )
strQuery.append("and a.idImportacao = :idImportacao ");
if (importarArquivoTransacaoForm.getLote() != null )
strQuery.append("and a.numeroLote = :pNumeroLote ");
if (importarArquivoTransacaoForm.getNomeArquivo() != null && !importarArquivoTransacaoForm.getNomeArquivo().trim().equals("") )
strQuery.append("and lower(a.nomeArquivo) like lower( :pNomeArquivo ) ");
if (importarArquivoTransacaoForm.getCnpj() != null && !Util.clearNumber(importarArquivoTransacaoForm.getCnpj()).equals(""))
strQuery.append("and a.cliente.cnpj = :pCnpj ");
if (importarArquivoTransacaoForm.getDataProcessamento() != null )
strQuery.append("and a.dataProcessamento >= :pDataProcessamento ");
if (importarArquivoTransacaoForm.getDataProcessamentoAte() != null )
strQuery.append("and a.dataProcessamento < :pDataProcessamentoAte ");
if (importarArquivoTransacaoForm.getStatus() != null && !importarArquivoTransacaoForm.getStatus().equals(""))
strQuery.append("and a.status = :pStatus ");
//ordenação da query
strQuery.append("order by a.numeroLote");
Query query = em.createQuery(strQuery.toString());
if (importarArquivoTransacaoForm.getIdArquivo() != null )
query.setParameter("idImportacao", importarArquivoTransacaoForm.getIdArquivo() );
if (importarArquivoTransacaoForm.getLote() != null )
query.setParameter("pNumeroLote", importarArquivoTransacaoForm.getLote() );
if (importarArquivoTransacaoForm.getNomeArquivo() != null && !importarArquivoTransacaoForm.getNomeArquivo().trim().equals("") )
query.setParameter("pNomeArquivo", "%" + importarArquivoTransacaoForm.getNomeArquivo() + "%");
if (importarArquivoTransacaoForm.getCnpj() != null && !Util.clearNumber(importarArquivoTransacaoForm.getCnpj()).equals(""))
query.setParameter("pCnpj", Util.clearNumber(importarArquivoTransacaoForm.getCnpj()));
if (importarArquivoTransacaoForm.getDataProcessamento() != null )
query.setParameter("pDataProcessamento", importarArquivoTransacaoForm.getDataProcessamento());
if (importarArquivoTransacaoForm.getDataProcessamentoAte() != null )
{
Calendar cal = Calendar.getInstance();
cal.setTime(importarArquivoTransacaoForm.getDataProcessamentoAte());
cal.add(Calendar.DAY_OF_MONTH, 1); //Adiciona Um dia
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
query.setParameter("pDataProcessamentoAte", cal.getTime());
}
if (importarArquivoTransacaoForm.getStatus() != null && !importarArquivoTransacaoForm.getStatus().equals(""))
query.setParameter("pStatus", importarArquivoTransacaoForm.getStatus());
lstArquivoImportacao = query.getResultList();
}
else
{
strQuery.append("order by a.numeroLote");
Query query = em.createQuery(strQuery.toString());
lstArquivoImportacao = query.getResultList();
}
return lstArquivoImportacao;
}
but the values are not changed, i could see the values changed if i put a tag "propagation: none" on the button that call the search method, but i lose the parameter from the form.
someone has a clue?
i tried to flush the entity manager in many places and change the transaction type but the values only changes with a click in a link with propagation="none"
A bit not-so-easy-to-read for non Portuguese(?)-speakers ;-)
If I understand your code correctly you are changing managed objects through the call of a stored procedure. This keeps the persistence contexts from being updated - a flush should have no effect (regarding this objects).
Refreshing these objects explicitly before you touch them should solve your problem (em.refresh()).
精彩评论