NHibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing. Type:

0

I'm having this problem, does anyone know how I can fix this problem?

This is my Nhibernate config code.

 public class NhibernateHelper
{
    private ISessionFactory sessionFactory;


    public static ISession GetSession()
    {
        return Instance.GetSessionFactory().GetCurrentSession();
    }

    public static ISessionFactory Test()
    {
        MemoryStream stream = new System.IO.MemoryStream();
        HbmSerializer.Default.Validate = true;
        HbmSerializer.Default.Serialize(stream, System.Reflection.Assembly.GetExecutingAssembly());
        stream.Position = 0;
        Configuration configuration= new Configuration();

        configuration.Configure();
        configuration.SetProperty("connection.connection_string", ConfigNhibernate.getConfig()); 
        configuration.SetProperty("current_session_context_class", "thread_static"); 
        configuration.AddInputStream(stream);
        stream.Close();

        Instance.sessionFactory = configuration.BuildSessionFactory();
        return Instance.sessionFactory;
    }


    public NhibernateHelper()
    {

        if (sessionFactory == null)
        {

            MemoryStream stream = new System.IO.MemoryStream();
            HbmSerializer.Default.Validate = true;
            HbmSerializer.Default.Serialize(stream, System.Reflection.Assembly.GetExecutingAssembly());
            stream.Position = 0;
            Configuration configuration= new Configuration();
            configuration.Configure();
            configuration.SetProperty("connection.connection_string", ConfigNhibernate.getConfig()); 
            configuracao.SetProperty("current_session_context_class", "managed_web"); //add essa linha
            configuracao.AddInputStream(stream);
            stream.Close();

            sessionFactory = configuracao.BuildSessionFactory();
        }
    }

    public static ISessionFactory SessionFactory
    {
        get { return Instancia.sessionFactory; }
    }

    private ISessionFactory GetSessionFactory()
    {
        return sessionFactory;
    }

    public static NhibernateHelper Instancia
    {
        get 
        {
            return CriarGerenciadorDeSessao.gerenciadorDeSessao; 
        }
    }

    public static ISession AbrirSessao()
    {
        return Instancia.GetSessionFactory().OpenSession();
    }

    public static void RecarregarSessao(object obj)
    {
        SessaoCorrente.Refresh(obj);
    }

    public static ISession SessaoCorrente
    {
        get
        {
            return Instancia.GetSessionFactory().GetCurrentSession();
        }
    }

    class CreateSessionManager
    {
        internal static readonly NhibernateHelper sessionmanager= new NhibernateHelper();
    }


}

    
asked by anonymous 03.04.2018 / 15:39

0 answers