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 719669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:40:11+00:00 2026-05-14T05:40:11+00:00

I’m working on setting up NHibernate for a project and I have a few

  • 0

I’m working on setting up NHibernate for a project and I have a few queries that, due to their complexity, we will be leaving as stored procedures. I’d like to be able to use NHibernate to call the sprocs, but have run into an error I can’t figure out. Since I’m using Fluent NHibernate I’m using mixed mode mapping as recommended here. However, when I run the app I get a “Named query not known: AccountsGetSingle” exception and I can’t figure out why. I think I might have a problem with my HBM mapping since I’m not very familiar with using them but I’m not sure.

My NHibernate configuration code is:

private ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2005
            .ConnectionString((conn => conn.FromConnectionStringWithKey("CIDB")))
                .ShowSql())
        .Mappings(m => 
            {
                m.HbmMappings.AddFromAssemblyOf<Account>();
                m.FluentMappings.AddFromAssemblyOf<Account>();
            })
        .BuildSessionFactory();
}

My hbm.xml file is:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <sql-query name="AccountsGetSingle">
        <return alias="Account" class="Core, Account"></return>
        exec AccountsGetSingle
    </sql-query>
</hibernate-mapping>

And the code where I am calling the sproc looks like this:

public Account Get()
{
    return _conversation.Session
        .GetNamedQuery("AccountsGetSingle")
        .UniqueResult<Account>();
}

Any thoughts or ideas would be appreciated. Thanks.

Update: @kibbled_bits’s suggestion get me the end result that I’m looking for (Being able to call a Stored Procedure from NHibernate), but I still don’t know why the approach I have listed above doesn’t work. I’m still curious as to why since it might provide valuable insight into future problems.

  • 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-05-14T05:40:11+00:00Added an answer on May 14, 2026 at 5:40 am

    When I have to use stored procedures (which only occurs when I’m forced to). I much rather use the following method to execute them:

    var list = Session.CreateSQLQuery("exec GetCustomerByNaturalKey ?, ?")
    .AddEntity(typeof(Customer))
    .SetInt32(0, customerNo)
    .SetDateTime(1, createdDate)
    .List<Customer>();
    

    The first parameter to .SetInt32/DateTime is just the ordinal position of the parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.