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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:08:15+00:00 2026-05-24T07:08:15+00:00

In NHibernate 3.1, ISession.SaveOrUpdateCopy() has been marked as deprecated. The documentation suggests using Merge()

  • 0

In NHibernate 3.1, ISession.SaveOrUpdateCopy() has been marked as deprecated. The documentation suggests using Merge() instead. The documentation for each is as follows:

SaveOrUpdateCopy(object obj)

Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with
the session, it will be loaded. Return the persistent instance. If the
given instance is unsaved or does not exist in the database, save it and
return it as a newly persistent instance. Otherwise, the given instance
does not become associated with the session.

Merge(object obj)

Copy the state of the given object onto the persistent object with the same
identifier. If there is no persistent instance currently associated with
the session, it will be loaded. Return the persistent instance. If the
given instance is unsaved, save a copy of and return it as a newly persistent
instance. The given instance does not become associated with the session.
This operation cascades to associated instances if the association is mapped
with cascade="merge".
The semantics of this method are defined by JSR-220.

They look nearly identical to me, but there are bound to be some subtleties involved. If so, what are they?

  • 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-24T07:08:16+00:00Added an answer on May 24, 2026 at 7:08 am

    SaveOrUpdateCopy is now considered obsolete and thus Merge is meant to take over for it (hence its extreme similarity).

    They are pretty much the same except I don’t think those cascade options were available with SaveOrUpdateCopy. However, that point is moot as Merge should be method you use.


    UPDATE: I went in to the source code of NHibernate just to make sure they are as similar as I was thinking and here is what I found.

    Both Merge and SaveOrUpdateCopy have very similar implementations:

    public object Merge(string entityName, object obj)
    {
        using (new SessionIdLoggingContext(SessionId))
        {
            return FireMerge(new MergeEvent(entityName, obj, this));
        }
    }
    
    public object SaveOrUpdateCopy(object obj)
    {
        using (new SessionIdLoggingContext(SessionId))
        {
            return FireSaveOrUpdateCopy(new MergeEvent(null, obj, this));
        }
    }
    

    Their FireXXXX methods are also very similar:

    private object FireMerge(MergeEvent @event)
    {
        using (new SessionIdLoggingContext(SessionId))
        {
            CheckAndUpdateSessionStatus();
            IMergeEventListener[] mergeEventListener = listeners.MergeEventListeners;
            for (int i = 0; i < mergeEventListener.Length; i++)
            {
                mergeEventListener[i].OnMerge(@event);
            }
            return @event.Result;
        }
    }
    
    private object FireSaveOrUpdateCopy(MergeEvent @event)
    {
        using (new SessionIdLoggingContext(SessionId))
        {
            CheckAndUpdateSessionStatus();
            IMergeEventListener[] saveOrUpdateCopyEventListener = listeners.SaveOrUpdateCopyEventListeners;
            for (int i = 0; i < saveOrUpdateCopyEventListener.Length; i++)
            {
                saveOrUpdateCopyEventListener[i].OnMerge(@event);
            }
            return @event.Result;
        }
    }
    

    The methods are exactly the same except they draw on different event listener lists, but even the types of the lists (IMergeEventListener) are the same!

    Looking at the listener lists, they are both initialized with a default listener. The default listener for the Merge listen handlers is of type DefaultMergeEventListener while the SaveOrUpdateCopy is DefaultSaveOrUpdateCopyEventListener. Thus, the difference between them is just the difference in these two implementations (that is if you keep the default listener, which is 99% of the time).

    However, the real interesting fact IS the difference in implementation. If you look at DefaultSaveOrUpdateCopyEventListener you get this:

    public class DefaultSaveOrUpdateCopyEventListener : DefaultMergeEventListener
    {
        protected override CascadingAction CascadeAction
        {
            get { return CascadingAction.SaveUpdateCopy; }
        }
    }
    

    This means the default behavior for Merge and SaveOrUpdateCopy only differs in the cascading actions, everything else is exactly the same.

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

Sidebar

Related Questions

I'm using Ninject, Fluent NHibernate and ASP.NET MVC. Up until now everything has been
What is the pros and cons using IStatelessSession over ISession in NHibernate?
Using NHibernate, is it possible to fill an existing object using the results of
We're using NCommon's UnitOfWorkScope which wraps nHibernate ISession functionality. Our goal is to eager-load
I'm using NHibernate to do database access in my application. My ISession s have
I'd like to have NHibernate call a stored procedure when ISession.Get is called to
I'm currently using StructureMap to inject instances of NHibernate ISessions using the following code:
NHibernate Version: 2.1 I'm using what seems to be a pretty standard HttpModule approach
Using NHibernate 1.x we encountered this error, suddently, during a nigthly job: 25/06/2012 22:50:59
Does nHibernate create code that has all the details of the column? I know

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.