Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to handle foriegn key in entity design?  RSS feed

 
xiaoma wang
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, everyone:
Currently i am working on an project which will use lots of entity beans. If the one table (called A) has a foreign key to another table (called B) and my two entity beans(let's call entity A and entity B) are built on the two table separately, what should i do if i want to delete one record in B? i need to delete the corresponding record in A first? Another word, must invoke the remove method in entity A first?
Regards
Xiaoma Wang
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using EJB 2.0 then the easy choice is CMR (Container Managed Relationships). Otherwise you will need to code this cascading delete logic in your entity beans or rely on the database.
 
Volodymyr Shram
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by xiaoma wang:
hi, everyone:
Currently i am working on an project which will use lots of entity beans.

Hi!
As for me, there is better way that can be used istead of using CMR relationships in your
project (expecially when your projecty is very large with many tables and many foreign keys).
When you you use CMR with your project you should use name agreement for your CMR-fields,
you have to care about uni- or bidirectional character of your relationships. And, as I got
during my project (more than 60 tables) applivcation server does re-mapping your CMR-fields
and, as a result, your project's operating speed are very low.
Of course, Chris Mathews is right -- using CMR fields are the easiest choice for developing
(in spite of some reservation like inserting new records in PostCreate and so on and much bigger
deployment descriptors) but you should pay some application spped for this simplicity.
IMHO better way to manage your FK logic via models for each tables, and use entity-beans for
deleting/inserting/updating needs only.
But, of course, it's up to you.
Regards.
 
xiaoma wang
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, chris and volodymyr:
Very much appreciate your advices and i will think about it for a while.
Cheers!
Xiaoma Wang
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!