• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping Entity type as a collection of another Entity type

 
Dinakar Manchi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have two entity types - Person and Car (Both have their own IDs)..... Person has an arraylist of Cars...such that even if person entity is deleted, the cars entity can still remain....I am confused as to how this mapping can be done in hibernate. Can anyone post me with an example that does something similar?

Thanks,
Dinakar.
 
Vijay Gadde
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dinakar,
I was having similar scenario in my current application like Each User will have different addresses like office,home and work.
when user de-register himself we delete the user record alone not the address. So you need to remove/should not have this foreign key relation-ship on the Cars table you need to maintain logical relation ship only So when user create... in your cars table you will have list of cars and NON MANDATORY USER_ID field along with Active-flag when user created first time you will just put USER_ID for all the array list of cars and when user deleted you need to change the status flag as in-active. Hope this solves your problem.
Thanks,
VIJAY.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this.

http://www.hibernate.org/hib_docs/reference/en/html/collections.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic