-1

So, I have a problem with FluentNHibernate. I've mapped all the properties, I've linked my tables and I get an error:

An invalid or incomplete configuration was used creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

Not really sure what was the issue because I created the mapping, classes and the database based on a previous program. The DataLayer class where I create the SessionFactory is:

namespace WTF.Edit1
{
    public class DataLayer
    {
    private static ISessionFactory _factory = null;
    private static object objLock = new object();


    public static ISession GetSession()
    {

        if (_factory == null)
        {
            lock (objLock)
            {
                if (_factory == null)
                    _factory = CreateSessionFactory();
            }
        }

        return _factory.OpenSession();
    }

    //konfiguracija i kreiranje session factory
    private static ISessionFactory CreateSessionFactory()
    {
        try
        {
            var cfg = OracleManagedDataClientConfiguration.Oracle10
            .ConnectionString(c =>
                c.Is("Data Source=datasource:1111/AAAA;User Id=user;Password=pass"));

            return Fluently.Configure()
                .Database(cfg)
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<KorisnikMapiranja>())
                .BuildSessionFactory();
        }
        catch (Exception ec)
        {
            System.Windows.Forms.MessageBox.Show(ec.Message);
            return null;
        }

    }
}
}

The specific class I want to place the info in the database is:

namespace WTF.Edit1.Podaci
{
    public class Korisnik
    {       
        public virtual string Tip { get; set; }
        public virtual string Ime { get; set; }
        public virtual string Prezime { get; set; }
        public virtual string KorisnickoIme { get; set; }
        public virtual string Lozinka { get; set; }
        public virtual string PonovljenaLozinka { get; set; }
        public virtual string Email { get; set; }
        public virtual string Pol { get; set; }

        public virtual IList<Recept> Recepti { get; set; }
        public virtual IList<Komentar> Komentari { get; set; }
        public virtual IList<Ocena> Ocene { get; set; }

        public Korisnik()
        {
            Recepti = new List<Recept>();
            Komentari = new List<Komentar>();
            Ocene = new List<Ocena>();
        }
    }

    public class User : Korisnik
    {
    }

    public class Admin : Korisnik
    {
    }
}

And the mapping is:

namespace WTF.Edit1.Mapiranja
{
class KorisnikMapiranja : ClassMap<Korisnik>
{
    public KorisnikMapiranja()
    {
        Table("KORISNIK");

        Id(x => x.KorisnickoIme, "USERNAME");

        Map(x => x.Ime, "IME");
        Map(x => x.Prezime, "PREZIME");
        Map(x => x.Email, "EMAIL");
        Map(x => x.Lozinka, "PASSWORD");
        Map(x => x.PonovljenaLozinka, "PASSREPEAT");
        Map(x => x.Pol, "POL");
        Map(x => x.Tip, "TIP");

        HasMany(x => x.Recepti).KeyColumn("USERNAME");
        HasMany(x => x.Komentari).KeyColumn("USERNAME");
        HasMany(x => x.Ocene).KeyColumn("USERNAME");
    }
}

class UserMapiranja : SubclassMap<User>
{
    public UserMapiranja()
    {
        Table("USERI");

        KeyColumn("USERNAME");
    }
}

class AdminMapiranja : SubclassMap<Admin>
{
    public AdminMapiranja()
    {
        Table("ADMIN");

        KeyColumn("USERNAME");
    }
}
}

Any ideas? I've tried to research and find the answers but nothing worked for me.

bobtimista
  • 9
  • 1
  • 1
  • 2
    Can you inspect the `InnerException` property of the top-level exception and add it to your question. It's usually well detailed and will often tell you the exact problem. – David Osborne May 24 '17 at 13:17

1 Answers1

0

You are probably missing the Oracle managed client. You require to have it referenced/reachable in order to use the OracleManagedDataClientConfiguration.

If possible, just install the corresponding package through nuget to see if that is what causing your Exception: https://www.nuget.org/packages/Oracle.ManagedDataAccess/

Install-Package Oracle.ManagedDataAccess

Fredy Treboux
  • 3,167
  • 2
  • 26
  • 32