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

  • Home
  • SEARCH
  • 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 9005569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:10:51+00:00 2026-06-16T01:10:51+00:00

I am using NHibernate & Net Persistence API with C# in my project. I

  • 0

I am using NHibernate & Net Persistence API with C# in my project. I have the following Save method:

        public void Save(IGenericEntity entity)
        {
            _entityManager = GetEm();
            _entityManager.GetTransaction().Begin();
            _entityManager.Persist(entity);
            _entityManager.Flush();            
            _entityManager.GetTransaction().Commit();            
            _entityManager.Clear();
        }

Now say entity has a field ID (which is auto-generated value from db). Now I am saving this entity, and I want either auto-generated ID or saved entity in return, but.Commit() return type is void. Anyone can please guide about this?

I have used hibernate with Java, and there by calling .save() it returns the saved entity (with auto-generated ID). How to achieve the same in above context?

  • 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-16T01:10:52+00:00Added an answer on June 16, 2026 at 1:10 am

    After the call to #flush your entity will have the id in it. Try this test:

    Save( entity );
    assertNotNull( entity.getId() );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using: ASP.NET MVC3 Ninject 2 Fluent nHibernate I have 2 databases (DB1 & DB2).
I've just started using Fluent NHibernate and have run into the following problem trying
I am using Fluent and NHibernate. I have two objects say A & B
I am getting the following error, Using asp.net and nHibernate. Databinding methods such as
in my mvc project im using nhibernate 3 as orm, but i have a
We are using Nhibernate 1.2 on a big .NET 3.5 C# project and we
I have a asp.net web application that is using Linq to NHibernate in NHibernate
Can I use NHibernate with my new ASP.NET 4.0 web Application without using Entity
Using Nhibernate and Fluent NHibernate for the mapping, I have a parent entity with
I am developing project using Spring , Struts2 & Hibernate . Now I want

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.