Does not enter into Oracle bank, with Nhibernate

Asked

Viewed 41 times

1

I have a problem in an application, developed in C#, that uses Oracle database, and access the database with Nhibernate.

When trying to perform the Saveorupdate() function, the Insert is not done and does not generate any errors. When performing Debug (via Visual Studio), no exception or error is generated.

Doing the "in hand" Insert, directly by SQL Developer, works normally. Only in the application that does not perform the insertion.

Could you help me?

Follows part of the code that is made the Insert.

public SenhaAtendimento GeraSenhaAtendimento(int unidadeId, TipoSenha tipoSenha)
    {
        var seq = 1;

        var maxIdCrit = DetachedCriteria.For<SenhaAtendimento>()
            .CreateAlias("Unidade", "u")
            .Add(Restrictions.Eq("u.Id", unidadeId))
            .Add(Restrictions.Eq("Tipo", tipoSenha))
            .SetProjection(Projections.Max("Id"));

        var lista = Session.CreateCriteria<SenhaAtendimento>()
            .Add(Subqueries.PropertyEq("Id", maxIdCrit))
            .List<SenhaAtendimento>();

        if (lista.Any())
        {
            seq = lista.First().Sequencia + 1;
        }

        var sa = new SenhaAtendimento()
        {
            DataAbertura = Now.Date,
            Tipo = tipoSenha,
            Unidade = new Unidade() {Id = unidadeId},
            Sequencia = seq
        };

            Session.SaveOrUpdate(sa);

        return sa;
    }
  • I was able to find the problem. It was necessary to open a transaction and commit, since the Saveorupdate() function does not autocommit.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.