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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:39:38+00:00 2026-05-22T18:39:38+00:00

I have an Class with property [Serializable] public class MyClass { public MyClass ()

  • 0

I have an Class with property

[Serializable]
public class MyClass    {



    public MyClass    ()
    {
    }




    public virtual System.DateTime Time        {
        get;
        set;
    }


    public virtual string Name        {
        get;
        set;
    }

    public virtual string Department        {
        get;
        set;
    }

    public virtual string Ip
    {
        get;
        set;
    }


    public virtual string Address        {
        get;
        set;
    }


    public override bool Equals(object obj)
    {

        if (obj == null)

            return false;

        MyClass    t = obj as MyClass    ;

        if (t == null)

            return false;

        if (this.Time  == t.Time  && this.Name== t.Name && this.Department== t.Department)

            return true;

        else

            return false;

    }

    public override int GetHashCode()
    {

        int hash = 13;

        hash = hash +

          (null == this.Time ? 0 : this.Time.GetHashCode());

        hash = hash +

          (null == this.Name? 0 : this.Name.GetHashCode());

        hash = hash +

        (null == this.Department ? 0 : this.Department.GetHashCode());

        return hash;

    }
}

I am having my Nhibernate mapping as

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NhibernateTest" assembly="NhibernateTest">
    <class name="MyClass" table="NhibernateTest">
        <composite-id>
            <key-property column="Time" type="DateTime" name="Time"></key-property>
            <key-property name="Name" type="string" column="Name" ></key-property>
            <key-property name="Department" type="string" column="Department" ></key-property>
        </composite-id>
        <property column="Ip" type="string" name="Ip" />
        <property column="Address" type="string" name="Address" />
    </class>
</hibernate-mapping>

I am trying to perform a bulk upload for some 40k data’s with using composite key. using the following code.

    public void StoreInRDBMS(List<MyClass> FileList)
    {

       ITransaction transaction = null;
        try
        {     
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            ISession session = OpenSession();
            using (transaction = session.BeginTransaction())
            {

                foreach (var File in FileList)
                {

                    session.SaveOrUpdate(File);



                }

                session.Flush();
                session.Clear();
                transaction.Commit();

            }

            session.Close();


            stopwatch.Stop();

            var time = stopwatch.Elapsed;





        }
        catch (Exception ex)
        {

            transaction.Rollback();

        }
    }

but the problem is , while iterating in the loop the second record in the list throws this error

{“a different object with the same identifier value was already associated with the session: NhibernateTest.MyClass, of entity: NhibernateTest.MyClass”}
though the records are unique. and also if at all its not it should update the same.

It works file if I flush the session after every iteration in the loop like

                foreach (var File in FileList)
                {

                    session.SaveOrUpdate(File);

                    session.Flush();
                    session.Clear();


                }

which should not be the case and even its talkin 17 mins for 40 k records if done by above method.
Can anybody help regarding the same.

  • 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-22T18:39:39+00:00Added an answer on May 22, 2026 at 6:39 pm

    Maybe?

    foreach (var File in FileList)
                    {
    
                        session.SaveOrUpdate(File);
                        session.ExecuteUpdate();
    
    
                    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter
Let's suppose I have this object: [Serializable] public class MyClass { public int Age
Lets say i have a class [Serializable()] public class Car { public string model;
I have a class property exposing an internal IList<> through System.Collections.ObjectModel.ReadOnlyCollection<> How can I
i have a class with a static public property called Info. via reflection i
I have a base class with a property which (the get method) I want
I have a class with a string property, having both a getter and a
I have a base class with a property called Name, which has an XmlText
I have a class hierarchy like this: @Entity @Table (name=call_distribution_policies) @Inheritance (strategy=InheritanceType.JOINED) public class
I have following entity class User: public class User implements Serializable { @Column(length =

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.