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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:27:03+00:00 2026-05-11T16:27:03+00:00

I have a domain object used in an identity map (the keys are the

  • 0

I have a domain object used in an identity map (the keys are the object’s Id property).

Pseudocode:

map = new Mapping();
map[domainObj.Id] = 'foo';

I observe the object to tell me when it has been saved to the database:

domainObj.bind('saved', function() {
    map[domainObj.Id] = 'new foo!'
})

For new objects the Id field is empty and not populated until it is saved to the database.

And therein lies my problem. In the case of new objects, the lookup “map[domainObj.Id]” fails because the object’s identity has changed after being saved!

What is the best way to use an object in an identity map like this?

Constraints:

  1. I am using a language that does not allow objects as keys in a mapping [JavaScript]
  2. The Id field must be generated on the server when saving a new object

Update

Thanks for the feedback. I really would like to have value objects mapped the same way as entities: just because the value object has not been saved does not mean it does not have a value to map to for my application. I am in fact mis-understanding what an identity map is (which, after re-reading the pattern definition, it turns out I am not truly using).

The solution I came up with is pretty much straight from Igor’s answer: each object gets a random id assigned to it upon instantiation. It is unique, immutable and unchanging during the lifetime of the context in which the object lives. It is there for both entities from the db and new instantiations. The tweak for entities is that it is set to match the real identity of the object. This makes debugging a bit easier. This is the value I use as the key in the mapping.

  • 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-11T16:27:04+00:00Added an answer on May 11, 2026 at 4:27 pm

    Until an object gets the identity, it’s just a value object. Only after the identity has been established it becomes an entity.

    Until the object becomes an entity you cannot really put it in an identity map like yours – it doesn’t make sense, since you cannot pull it out (since you don’t have a unique key to find it).

    One possible approach:

    1. Add a flag to the class which indicates the state of the object (new / saved).
    2. Implement a temporary (client-side) ID for these objects
    3. Optional:
      1. keep “new” objects in a separate identity map (if you cannot avoid ID conflicts between client and server IDs)
      2. keep “new” objects in the same identity map (if you can avoid ID conflicts between client and server IDs)
    4. Once the object has been saved, replace the client ID with the server ID, set the state to saved, move to the main identity map (if necessary).

    See here about the entities vs. value objects

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

Sidebar

Related Questions

I have a Domain object called User and UserCreateViewModel.Automapper is used for mapping from
I have a property on a domain object that is declared in a many-to-one
I have a domain object that is used throughout my application. I'm writing a
So let's say we have a domain object such as the following public class
I have a basic domain object, say like Person or Campaign or Event that
I have the current basic structure for each domain object that I need to
Let's say I have an interface representing a domain object: public interface IFoo {
I have a domain object that stores some metadata and some raw bytes. This
I have a domain object that has been auto generated for me by MyGeneration.
My use case is simple. I have a root domain object which references a

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.