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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:16:58+00:00 2026-05-31T00:16:58+00:00

I have mapped classes with custom sql (insert, delete, update) through procedure calls. But,

  • 0

I have mapped classes with custom sql (insert, delete, update) through procedure calls. But, I noticed that when my insert procedure fails raising exception, the GenericAdoException from NHibernate doesn’t have my message raised from the procedure.

But, all raised exceptions from procedures for delete and update is catched well, only the insert procedure hasn’t its exception message catched.

Is that a limitation or a bug of NHibernate 3.2.4 when we use “native” generator for ids combined with custom sql ?

I’m searching also ways to get some out parameters from that procedures like a timestamp to each event (insert, delete and update), the timestamp is generated inside procedures.

EDIT: OUT PARAMs – I found the “generated” option over properties mapping options which we can ask to NHibernate to get params from procedures. This means that these properties have genarated values. So I tried to use generated=”always” and works for insert, update and delete operations. Example: <property name="MyProp" generated="always"/>

  • 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-31T00:16:59+00:00Added an answer on May 31, 2026 at 12:16 am

    I found that sql server driver doesn’t put the messages raised by stored procedures into the SqlException when you run these stored procedures with ExecuteReader(). On the other hand NHibernate executes the custom sql-insert with ExecuteReader() (I debbuged its source code) and I guess it’s right and necessary to get the key when it’s mapped with native (or identity), my case.

    Well, and now what to do ? I found also (hard to found) that the SqlConnection has a event called “InfoMessage” in which you can receive (catch) all messages sent from your stored procedures (raiserror). Now this is possible to “catch” these messages, but how to make them cross NHibernate core and be received by our application when we insert something session.save() ?

    Altough we have access to session and so to the connection (SqlConnection) the messages was already lost, because them are only received by the delegate assigned to the event SqlConnection.InfoMessage before of its occurrence.

    To solve this, I tried two approaches:

    • In the first I projected a way to register the delegate inside DriverConnectionProvider.GetConnection() and this delegate would store the messages on the thread context associating it with the connection, so these messages could be getted later.
    • In the second and the one choosed, I implemented IDbConnection and IDbCommand wrapping inside them the SqlConnection and SqlCommand (but I think the NHibernate has a bug because in some places it references DbConnection instead IDbConnection – like in ManagedProviderConnectionHelper, so I had to extend from DbConnection and DbCommand instead).

    Inside my CustomSqlConnection I register the delegate and store the messages for later use.
    This is working ! Work as standalone driver (ADO) either as a NHibernate driver.

    The idea is:

        public class CustomSqlConnection : DbConnection, IDbConnection {
            private SqlConnection con;
            private StringBuilder str = new StringBuilder(0);
    
            public CustomSqlConnection() {
                con = new SqlConnection();
                con.InfoMessage += OnInfoMessage;
            }
    
            private void OnInfoMessage(object sender, SqlInfoMessageEventArgs e) {
                if (str.Length > 0) {
                    str.Append("\n");
                }
                str.Append(e.Message);
            }
    
            public string FetchMessage() {
                string msg = Message;
                str.Clear();
    
                return msg;
            }
    
            ...
            ...
        }
    

    EDIT: The hard step is to implement all operations from DdConnection and Dbcommand, repassing the call to the sql instance (look the field con above), so:

            ...
            public override void Open() {
                con.Open();
            }
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ORM mapped object, that I want to update. I have all
I have the following 3 classes(mapped to sql tables). Places table: Name(key) Address Capacity
I have a hierarchy of classes mapped into hibernate that looks kind of like
I have mapped several java classes like Customer, Assessment, Rating, ... to a database
I have the directory mapped on my machine so that I can browse and
I have an object that is mapped to have a set of objects, very
I have the following mapped classes Trade { ID, AccountFrom, AccountTo } Account {ID,
I have a custom framework that, following the advice in Apple's Framework Programming Guide
I have a small schema consisting of ~10 classes mapped by jpa2 with hibernate
I have the following mapped classes: <class name=Company table=Company> <id name=ID column=CompanyID> <generator class=native/>

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.