This tutorial will show you how to create master-detail relationships between view objects on the model layer. In this example we will create multiple levels of parent/child relationships.
Before you start this ADF tutorial
Before proceeding, make sure you have:
- An Oracle 11g database that is installed and running with the bisample dataset.
- Credentials and permissions, and a preconfigured connection to access the hrsample database.
- Access to the Oracle Jdeveloper environment.
Everything in place? Then you’re ready to get linking.
Building a new web application
The first task is to build a new web application that will allow us to use the relationships we create.
- From within the Jdeveloper environment, select the New Application option on the left.
- When the Name your application dialog screen pops up, give the app a suitable name – in our example we have chosen TestApp. Make sure that Fusion Web Application (ADF) is selected in the Application Template selection at the bottom of the dialog.
You can leave the default values in the other fields. At this point no further configuration is required, so you can click Finish to close the dialog. - In the Projects subsection of the Application Navigator pane, right-click on the Model entry and select New
- In the New Gallery dialog, select ADF Business Components from the left-hand pane. Next choose Business Components from Tables in the main pane.
Click OK to close the dialog. - On the Initialize Business Components Project dialog, click the green + icon next to the Connection: dropdown
- On the Select IDE Database Connection screen, choose the hrconn option from the IDE Database Connections pane and click the Copy Connection button.
- When you are returned to the Initialize Business Components Project dialog, click OK to continue.
Adding objects to your new web application
With the basics of configuration done, the next task is to add view objects.
- Click Model in the left-hand Application Navigator – a Create Business Components from Tables dialog will open. Click the Query button on the right to load a list of available tables. The wizard will then generate a list of Available Tables; highlight the tables shown below and click the > button to move them to the Selected list on the right.Click Next.
- The Read-Only View Objects page will now be displayed. Highlight all of the table names in the Available column, click the > button so that they move across to the Selected column.Click Next.
- Leave the default options selected on the next page (Read-Only View Objects) and click Next.
- Leave the default options selected on the Application Module page and click Next.
- Complete the Business Object creation process by clicking Finish.
The process may take a few minutes depending on how many view objects were selected.
Checking the Master-Detail-Detail view properties
Next we need to ensure that all of the views are performing correctly.
- From the Application Navigator pane, right click AppModule and select Open AppModule from the context menu
- When the Data Model pane opens, you will see the available relationships in the Data Model: side of the lower panel. You can remove any which are unnecessary for this app:Leaving the unnecessary modules in place will have no negative effect, but they do make it slightly harder to see what we are trying to achieve.
- Now we wen need to add the Child relationships to complete the Detail views. Locate the following View Objects in the left-hand pane and click the > button to add them to the Data Model:
* LocationsView
* DepartmentsView
* EmployeesViewYour Data Model should now look like this:
Make sure you save the project. - You can now see the relationships in the Data Controls tree view pane which can be expanded to reflect the model created in step 3:The relationships are now ready to test.
Testing the Master-Detail-Detail views
Testing the newly created relationship views is relatively straightforward:
- Right-click on the AppModule node in the Projects tree view pane and select Run from the context menu.
- After a few seconds the Oracle Business Objects Browser will open up to show your tree view list of components on the left. Double-clicking on any of these entries will show a single record detail in the pane on the right:
By selecting a specific Region, like Asia as shown above, then double-clicking the CountryRegFkLink1 tree view item, you will then see a list of child records:
You can repeat this process for each of the foreign key entries in the tree to access records at the very lowest level – in the Employees view. You can also enter new text into any of the fields on the right and click the green tick icon to save your changes.
And there you have it. A working master-detail object.
Watch Our Video On How To Create Master-Detail Relationships
Subscribe to our Youtube channel to watch this video.
Please Share This Knowledge With Others!