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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:50:39+00:00 2026-05-31T21:50:39+00:00

When you have an entity, such as UserEntity, who’s id property is derived from

  • 0

When you have an entity, such as UserEntity, who’s id property is derived from its primary key in the db – should you provide a setter method such as setId()?

Some arguments against:

  • opens the door to possible accidental overwrites of other UserEntities in the db
  • two (or more) UserEntities could exist at any time with the same id but different properties. (if I pulled 3 different Users from the db and set their id values to the same)

Some arguments for:

  • if I don’t HAVE to instantiate the UserEntity with an id in the constructor (since it has a setter method), I can use the methods of the UserEntity object with temporary / fake / new user values…without having to persist it first.

Provide a setter (and don’t force an id in the constructor), or force an id in the constructor, and remove the setter?

  • 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-31T21:50:40+00:00Added an answer on May 31, 2026 at 9:50 pm

    The identity value of an entity should be managed by the persistence layer and ideally would not be settable by anything else – the persistence layer should assign a new identity value upon persistence and set it upon retrieval. Furthermore, you should be able to use a transient (not persisted) entity without needing access to its identity. Allowing the identity to be set through the constructor can lead to issues because there is no authoritative source for identity values. One example where identities can be assigned from external sources is if a client requests that a newly persistence entity has a UUID as it’s identity, though this example is contrived.

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

Sidebar

Related Questions

I have Document entity having read-only (from client perspective) property modificationAuthor (I want it
I have entity e.g. Product which aggregates other entities such as Category . Those
I have an Google App Engine entity called MyFile. It has properties such as
I have Employee table and an Entity class for it, My task is such
I have a User entity which has a HasCompletedSecurity property which indicates whether that
I have an entity ArticlePattern , which has a property pattern (string). I need
If I have an entity such as the following: @Entity public class Customer {
I have an entity object which contains two element collections as such: @Entity public
I have an Entity set that has Entities with a compound key containing ID
I have extended an Entity Framework 4 entity class with a calculated property in

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.