Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:12:41+00:00 2026-06-15T12:12:41+00:00

I am using an Oracle Database with NHibernate 3.3.2.4000. I have a unit test

  • 0

I am using an Oracle Database with NHibernate 3.3.2.4000.

I have a unit test set up to verify that an entity collection can be selected from the table. Here’s what it looks like:

[TestFixture]
public class UnitOfWorkIntegrationTests
{
    private IUnitOfWork _unitOfWork;
    private INHibernateSessionFactory _nHibernateSessionFactory;
    private IActiveSessionManager _activeSessionManager;

    [SetUp]
    public void BeforeEachTest()
    {
        _nHibernateSessionFactory = new NHibernateSessionFactory();
        _activeSessionManager = new ActiveSessionManager();
        _unitOfWork = new UnitOfWork(_nHibernateSessionFactory, _activeSessionManager);
    }

    [Test]
    public void ShouldFetchOAuthMemberships()
    {
        var oauths = _unitOfWork.OAuthMemberships.ToArray();
        oauths.ShouldNotBeNull();
    }
}

The line that fetches my OAuthMemberships collection is throwing this exception:

could not execute query

[ select oauthmembe0_.id as id13_ from bckgrd_booklet_app.OAuthMembership oauthmembe0_ ]

[SQL: select oauthmembe0_.id as id13_ from bckgrd_booklet_app.OAuthMembership oauthmembe0_]

My OAuthMembership class and mapping are below. As you can see I am defining the table name as "OAUTH_MEMBERSHIP", but the generated SQL includes the camel-cased class name instead. I have no table name conventions defined. Why does NHibernate ignore my Oracle-cased table names?

public class OAuthMembership
{
    public virtual int Id { get; set; }
    public virtual string Provider { get; set; }
    public virtual string ProviderUserId { get; set; }

    public virtual UserProfile UserProfile { get; set; }
}

public class OAuthMembershipMap : ClassMapping<OAuthMembership>
{
    public void OAuthMembership()
    {
        Table("OAUTH_MEMBERSHIP");

        Id(x => x.Id, m => m.Column("ID"));
        Property(x => x.Provider, m => m.Column("PROVIDER"));
        Property(x => x.ProviderUserId, m => m.Column("PROVIDER_USER_ID"));
        
        ManyToOne(x => x.UserProfile, m => m.Column("USER_PROFILE_ID"));
    }
}

Here’s my NHibernateSessionFactory:

public interface INHibernateSessionFactory
{
    ISession Create();
}

public class NHibernateSessionFactory : INHibernateSessionFactory
{
    private static readonly ILog Log = LogManager.GetLogger(typeof(NHibernateSessionFactory).Name);
    private readonly static ISessionFactory SessionFactory;
    public static string ConnectionString
    {
        get
        {
            return ConfigurationManager.ConnectionStrings["MyConnection"].Return(x => x.ConnectionString,
                "Data Source=myServer;User ID=bckgrd_booklet_app;Password=myPass;");
        }
    }

    static NHibernateSessionFactory()
    {
        try
        {
            var mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());

            HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            var configure = new NHibernate.Cfg.Configuration().Configure();
            configure.AddMapping(domainMapping);
            configure.BuildMappings();
            configure.DataBaseIntegration(x =>
            {
                x.Driver<OracleClientDriver>();
                x.Dialect<Oracle10gDialect>();
                x.ConnectionStringName = ConnectionString;
            })
            .CurrentSessionContext<WebSessionContext>();
            SessionFactory = configure.BuildSessionFactory();

        }
        catch (Exception ex)
        {
            Log.Error("NHibernateSessionFactory did not initialize correctly.", ex);
            throw;
        }
    }

    public ISession Create()
    {
        Log.Debug("Creating new session.");
        return SessionFactory.OpenSession();
    }
}

My ActiveSessionManager:

public interface IActiveSessionManager
{
    void ClearActiveSession();
    NHibernate.ISession GetActiveSession();
    void SetActiveSession(NHibernate.ISession session);
}

public class ActiveSessionManager : IActiveSessionManager
{
    [ThreadStatic]
    private static ISession _current;

    public ISession GetActiveSession()
    {
        return _current;
    }

    public void SetActiveSession(ISession session)
    {
        _current = session;
    }

    public void ClearActiveSession()
    {
        _current = null;
    }
}

Relevant parts of my UnitOfWork definition:

public interface IUnitOfWork
{
    //...
    IQueryable<OAuthMembership> OAuthMemberships { get; }
    IQueryable<T> All<T>();
    //...
}

public class UnitOfWork : IUnitOfWork
{
    private readonly ISession _session;

    //...

    public IQueryable<OAuthMembership> OAuthMemberships
    {
        get { return All<OAuthMembership>(); }
    }

    public UnitOfWork(
        INHibernateSessionFactory sessionFactory,
        IActiveSessionManager activeSessionManager)
    {
        _session = sessionFactory.Create();
        activeSessionManager.SetActiveSession(_session);
    }

    public IQueryable<T> All<T>()
    {
        return _session.Query<T>();
    }

    //...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:12:42+00:00Added an answer on June 15, 2026 at 12:12 pm

    I found my error after adding Fluent NHibernate to my project and making the same error there.

    My OAuthMembershipMap doesn’t have a constructor. I had mistakenly added a void method called OAuthMembership instead, so my table mapping and my Id and Property mappings failed. See the corrected code:

    public class OAuthMembershipMap : ClassMapping<OAuthMembership>
    {
        public OAuthMembershipMap()
        {
            Table("OAUTH_MEMBERSHIP");
    
            Id(x => x.Id, m => m.Column("ID"));
            Property(x => x.Provider, m => m.Column("PROVIDER"));
            Property(x => x.ProviderUserId, m => m.Column("PROVIDER_USER_ID"));
    
            ManyToOne(x => x.UserProfile, m => m.Column("USER_PROFILE_ID"));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to an Oracle Database using nHibernate. I can connect
I'm using NHibernate on a legacy database with Oracle 8i client. I can perform
I have a JRuby project that connects to an Oracle database using JDBC via
I have some Java code that connects to an Oracle database using DriverManager.getConnection(). It
I'm trying to connect my application with an Oracle database using NHIBERNATE 3.1.0.4000 version
I am using Fluent NHibernate on a project that has an Oracle 10g database.
Using oracle database. Here's how i think the SQLException happens... Say i have two
I have a PHP application using an Oracle XE database. Whenever I add a
I have a data mart mastered from our OLTP Oracle database using basic Materialized
I am using Fluent NHibernate's (1.0 RTM) automapping feature to create my oracle database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.