• Post Reply Bookmark Topic Watch Topic
  • New Topic

Referential Integrity

 
xiaoyu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to J2EE and EJB. I have a general design question:
In Container Managed Persistence, who is responsible for the referential integrity. Container or database constraint?
[ January 17, 2002: Message edited by: xiaoyu ]
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is whichever you choose. If you have constraints on the database then if your code tries to do anything that breaks integrity then the transaction will rollback upon commit.
On the other hand, you can implement constraints in your EJB code to make sure that you can't do anything that would break relational integrity.
Kyle
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xiaoyu,
Please re-register with a name that meets the naming requirements for JavaRanch. You must use your real first name - space - real last name.
Thanks,
Tom - Moderator of this forum
 
xiaoyu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the usually practice then? My previous experience is to use database constraint whereever possible.
I have another related question. Four entity beans form the following relations:
A--B--C--D
Entity Bean A has an indirect relation with Entity Bean D. Do I need to create a foreign key for table A or D to related them? Or I can use the relation through B and C?...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!