Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to handle foriegn key in entity design?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic