Main Menu
Lecture 1
Lecture 2
Lecture 3
Lecture 5
Lecture 6
Lecture 7
 

 

 

Mapping from Database Table to Java Class

Entity - maps the table to the class.

Student Table-> Student.java

Simple attribute - maps a column in the table to a variable in the class - these store values

Students Name -> String studentName;

Primary key - an entity has an attribute guaranteed to have a unique value for each row - they do not normally appear in an application because the objects are uniquely identified by their reference in memeory

Foreign key - a primary key from another entity stored in a column in this entity - serves to identify a relationship between the two identities

Relationships

Represented by a correspondence between a foreign key column of one table and the primary key column of another table

To find which rows are related, you must do a join operation.

In the application the relationship is represented by an instance variable. Which is either a reference to anther enterprise object in a one-to-one relationship.
Or a reference to an array of enterprise objects in a one-to-many relationship.

When you fetch records from a database, EOF executes a join to determine the related records and initialises the instance variables. No SQL is required. In fact it will traverse relationships for you if you need the data from that relaionship.

Many to Many relationships

Require an additional table in the database which contains columns for the primary keys for both entities.

e.g. a student is enrolled in many tutorials and a tutorial has many students.

Resolving these relationships requires two joins.

Student -> Join Table -> Tutorial
Or Tutorial -> Join Table -> Student

WO however handles this traversing for us.

Simplified in the object model - no class corresponding to the extra join table, unless the join table has its own unique attributes.

Flattening relationships

When entity A is related to entity B which is related to entity C

You want the relationship between A and C