I have told how to create Entity Object. If you look at very closely an EO is based on a single table.Now think about the scenario where there are two tables. Table one and table two and they are connected via foreign key relationship. So Entity Object one and Entity Object two must be connected via some link. This link is called Association.
If the foreign key relationship is there , JDeveloper can create the relationship automatically. This relationship is called Association.So in other words , an association is a relationship between source and destination Entity Objects.
Rules for Creating Association:
1. For two connecting EOs say Employee and department the Naming convention will be employeeDepartmentAssoc i.e the table1table2Assoc
2. Follow the camel case structure.
3.Suffix Assoc is written to clearly understand the association.
Case-1. If you have the database ready the association is done by JDeveloper itself
Case-2: if you do not have the direct association between themselves follow the below written steps.
Step-1: Click on File->New
Step 2: Select ADF Business Component from Business Tier from left pane.Select Association from right pane.click on OK.
Step-3: if the database is not connected we might get a database connection prompt. Connect to the correct database and click on next.Provide Name of the association.Click on Next.
Step-4: Here we will be getting two Entity Objects. Select the source and destination Entity Object to create an association.
The other thing we need to take care is Cardinality.The different cardinalities are…
- One to many
- many to one
- many to many
During runtime programmatically application can determine for how many rows of the first table can access how many rows of the second table.
Step-5: Expand the EOs to establish a connection between themselves. When done the below section will activate
Source and Destination Attribute: Below of the settings , there is another attribute list called source and destination attribute. It will clearly tell you association setting with the degree of Cardinality.
Click on Next.
Step-6: This page talks about more details about Accessors. The option of exposing accessors in the optional Java class that backs an entity object.
These assessors will give freedom to traverse between themselves programmatically
Step-7: On the same page the last point is Composition Association . There are two types of associations..
Reference The association references a destination entity object
Contains The destination entity can be thought of as a logical subpart of the source
Enable that by clicking on the on/off switch.
Click on Next
Step-8: If we need to change query and add some more options , this is the page to fine tune and add query clause.
Click on Next.
Step-9: This is the summary page of what the association we have made.
Click finish to create association successfully.
Any point of time we can go back and change the wizard(code).
Step-10. Double click or expand your folder for the association.
This is how we can create an association through ADF via JDeveloper.
Photo credit : http://kingsway.dnn.appros.net