# What Is a View Link

A View Link specifies a relationship between two View Objects. As such, it is an expression of an association defined either by underlying Entity Objects or by literal SQL statements. A View Link specifies source and destination View Objects, and links them using attributes selected by those View Objects. A View Link can be traversed from master to detail, but not from detail to master.

A View Link is a property of a package. You can use the View Link Wizard to:

- Define a View Link at design time to use in an Application Module. Such View Links can be reused by multiple Application Modules.

- Create accessor methods in the source View Object and possibly the underlying source Entity Object. You can use these accessor methods to programmatically access a desired result set in the View Object. You can also access a result set directly on the Entity Object.

> Note: You can also create a View Link dynamically at runtime through the Business Components for Java API.

If the View Link is based on an existing association, and the association has been defined as a composition, then when creating a detail View Row, the master View Row must exist and have non-null key values. If the association has not been defined as a composition, no such restriction applies.

## About associations and view links

Entity Objects represent tables, and an Association defines a relationship between two Entity Objects. Similarly, View Objects represent views of tables, and a View Link defines a relationship between two View Objects. Just as View Objects can be based on Entity Objects, View Links can be based on Associations. In either relationship, one end is the source, the other end is the destination.

One difference between associations and links is that associations are bidirectional; links are navigable in one direction only. For example, suppose two tables have a master-detail relationship based on a foreign key. The corresponding Entity Objects are related via an Association, and View Objects based on those Entity Objects are related by using a View Link based on the Association. The master end of the relationship is the source, the detail end is the destination.

One of the key features of associations is that the Business Components for Java framework generates accessor methods to traverse the association. This feature lets you get and set at the destination end of the association.

The following figure shows how Business Components for Java represent a master-detail relationship between the DEPT and EMP tables. It also shows how a client might use the objects to display linked data in a form.

Business Components for Java can model more complex relationships involving multiple tables, as well. As the following figure illustrates, you could use View Links to define a one-many-many relationship between customers and orders, and orders and items.