Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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 ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

one-to-one relationship  RSS feed

Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supose i've got to entities: PERSON and CAR.
They had a one-to-one relationship, in the CAR's table there is a foreign-key to PERSON - CO_PERSON.
Do i have do map the CO_PERSON as a cmp-field and then make the relationship? Or i just have to make the relationship and put the name of the field?
Cowgirl and Author
Posts: 1589
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- if I understand this correctly... if you have a one-to-one relationship between CAR and PERSON, and they are both entities, and you want it to be bi-directional (where CAR has a reference to PERSON and PERSON has a reference to CAR), then you can start with the PERSON entity and define a CMR field that holds the local component interface for the CAR entity, and then set-up a relationship for CAR and PERSON in the deployment descriptor. Also, since it is bi-directional, be sure to put a CMR field for PERSON inside the CAR bean (again, which references the local component interface for the PERSON).
If you want it to uni-directional, where PERSON has a reference to CAR, but CAR does not need a reference to PERSON, then define a CAR CMR field inside PERSON, but don't put any CMR field for PERSON inside CAR. Then when you define the relationship between them in the DD, you will *not* list a CMR field for the CAR side of the relationship.
And remember, you can also choose to define a cascade-delete, if you want the CAR to be automatically deleted if the PERSON is deleted. In that case, just be sure to put the cascade-delete tag inside the CAR side of the relationship. By saying that CAR has a cascade-delete capability, this means that if the other partner in the relationship is removed, then CAR will be removed automatically. Cascade-delete tags say to the Container, "Delete ME if my relationship partner is deleted." (in other words, do a remove() on me if someone does a remove() on my partner).
You probably wouldn't want to set up a cascade-delete for the PERSON, because that would mean that if the CAR is removed, the PERSON will be deleted as well! That would be like saying, "If my car is totalled (wrecked in an accident), you might as well kill me too..."
OK, so that's more than you needed to hear... but I was on a roll.

"If you like the book, don't tell me... tell Amazon."
- a starving writer
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!