Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Two identical entities with similar attributes.

 
Ranch Hand
Posts: 230
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I heard a technical scenario where 2 entities having same attributes. A Boy and Girl Entity with Name, Age and DOB. How this can be formed as single entity so that fields are not repetitive ? Please share any idea. I'm also keen to find the right solution through studies. But your ideas may also help. Thanks.

Regards,
Mohammed Sardar
 
Saloon Keeper
Posts: 12405
269
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehh, how about a 'person' entity with a 'gender' field?
 
Mohammed Sardar.
Ranch Hand
Posts: 230
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Ehh, how about a 'person' entity with a 'gender' field?


Thanks, so "Gender" as @Embedded you mean ? Can you elaborate please ?
 
Stephan van Hulst
Saloon Keeper
Posts: 12405
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that Gender would be so complex to warrant an embeddable type. Just use an enum for Gender and you can annotate the gender field with @Enumerated in your Person entity.
 
Mohammed Sardar.
Ranch Hand
Posts: 230
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I don't think that Gender would be so complex to warrant an embeddable type. Just use an enum for Gender and you can annotate the gender field with @Enumerated in your Person entity.


Stephan, by your idea what I understand is change to the db design of table structure itself. Instead having two tables (Boy and Girl) have one table with the name PERSON with attributes(NAME, AGE, DOB, GENDER(ENUM)) and represent the above Person table as a single Entity. Am I on track to get the above ?

Thanks & Regards.
 
Stephan van Hulst
Saloon Keeper
Posts: 12405
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, although I don't know why you would want to have an age field if you already have a date of birth field.
 
Mohammed Sardar.
Ranch Hand
Posts: 230
1
jQuery Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Yes, although I don't know why you would want to have an age field if you already have a date of birth field.



True, may be Edit button was disabled !!!
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic