• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why or (when to) use Entity Relationship ?

 
Pinal N Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,
If tables in a db already have a relationship among them, then what is the advantage of using Entity Relationship. I am having a hard time understanding when to use this functionality. I appreciate if someone could shed some lights on this.
Thanks & Regards,
Pinal.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Entity relationships are the object equivalents of the table relationship. They allow you to traverse the relationships between the tables as object links.
So, if you have a PERSON_TABLE that contains foreign keys to an ADDRESS_TABLE you need to be able to figure out which Person EJB corresponds to which Address EJB. That's what entity relationships give you.
They allow you to say myPerson.getAddress() and get back the right Address Entity bean corresponding to the right person.
Kyle
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
They allow you to say myPerson.getAddress() and get back the right Address Entity bean corresponding to the right person.

Additionally they allow you to write EJB-QL queries that navigate between objects as you would perform a SQL join without loading the intervening beans. For example, if Kyle's ADDRESS_TABLE had a relationship to a COUNTRY_TABLE, you could find all PERSONs for a particular country without dealing with ADDRESSes at all:

This would generate and execute SQL like (assuming 1:N from Person to Address)
 
Bish Ach
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In enterprise solution entity EJB represents Database Data.Database data consists of multiple tables with relations.. Now if u want to modify those data in the database through ur enterprise application; we need the same relationship betn diff Entity EJB in JVM. So that any change of the object in the JVM can reflect in the Database.
[ December 09, 2003: Message edited by: Bish Ach ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!