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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:52:09+00:00 2026-06-06T11:52:09+00:00

If you have a user entity, you could store his/her address in two ways.

  • 0

If you have a user entity, you could store his/her address in two ways. You could store all of the fields in the user object directly -or- you could create an address object which is persisted in a separate table and joined to the user (or cascaded, or whatever) and put into an address object inside the user entity.

What is the advantage of doing the latter? If you can fit more stuff into a single table, doesn’t that make the most sense? I would presume the latter would end up incurring more resource usage. I get that it can be more practical for other things, but the example specifically mentions a situation where you could do either.

Is a user something you would generally use an IdClass for, if you did something similar to what I’ve described above?

For an IdClass, must EVERY field simply be a key to another entity, or can you have concrete or transient fields there in addition? Is usage of @IdClass simply saying to expect multiple Id annotations, and the rest is up to you?

Thanks!

  • 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-06T11:52:10+00:00Added an answer on June 6, 2026 at 11:52 am

    You User to address relationship should be many to one. Because one user may have two addresses. If you going to put address object inside the user object you can have only one address for a user. Having the address fields in user object is also having that issue. So both your suggestions are not the best practices.

    No need to use a IdClass for User entity you can simply use database native id genoration by annotations. `@Id @GeneratedValue(strategy=GenerationType.IDENTITY).

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

Sidebar

Related Questions

I have two classes, user and role, defined as: public class User : Entity
it's possible to have one entity object (class, e.g. User) for more entity models
I have the following two entities: @Entity class Relation{ @ManyToOne private User user; //some
In our application, I have seen code written like this: User.java (User entity) public
I have a 'vanilla' install of CodeIgniter 2 + Doctrine 2. My tutorial Entity.User.dcm.yml
I have an entity loaded by Hibernate (via EntityManager ): User u = em.load(User.class,
Ok, I have a User entity as follows <?php class User { /** *
I have an Entity called User. User should be used in multilingual environment So
I have a simple examle domain of two aggregate roots and one regular entity.
When you have an entity, such as UserEntity, who's id property is derived from

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.