The application to build reflects the Model-View-Controller architecture. The model is provided by EJB Components, while the view and controller are provided by JavaServer Faces.You use the ADF Faces set of JSF-compatible components to build a richer web interface.
This tutorial requires to have JDeveloper 11.1.2. installed and to have access to an Oracle database 10g and onward with access to the HR schema.
-
Start JDeveloper by selecting Start > All Programs > Oracle Fusion Middleware 11.1.2.0.0 > JDeveloper Studio 11.1.2.0.0
-
If prompted for a Role, choose Studio Developer (All Features) and click OK.
Close the Tip of the Day window.
Once loaded, the JDeveloper IDE appears. Read more...
The very first time you open JDeveloper, the Start Page displays. You can re-invoke the Start Page later by choosing Help | Start Page.
Notice the various options available to help you learn about JDeveloper. After exploring these options, click the X on the Start Page tab to close it. (the X appears when you mouse over the tab).-
Click the Application Navigator tab to go back to the Application Navigator. Click the New Application icon.
-
In the New Gallery, select the Fusion Web Application (ADF) option.
Click OK.
-
In the Create Application dialog box, enter the Application Name HR_EJB_JPA. Notice that as you enter the application name, the directory name changes automatically. Enter oracle as the Application Package Prefix.
Choosing the Fusion Web Application option creates 2 projects. Read more...
Clicking Next on each page of the wizard and leaving the default values shows you the project names and package names that are going to be used. It also allows you to select specific features for the Model and ViewController projects.
The default name for project 1 is Model as the project name and oracle.model as the package name.
The default name for project 2 is ViewController as the project name and oracle.view as the package name.Click Finish. Wait for JDeveloper to create your application environment.
-
The Application Navigator displays the two projects created. On the right pane, notice the application overview allowing you to keep track of the steps as you complete them.
There are now 2 projects in your application. Read more...
The Model project is empty and will be populated with EJB JPA components after the creation of a database connection.
The ViewController project contains the basic components for building the UI.
The Overview pane guides you through your application development. You can use it and follow the step-by-step instructions to build your applications.
-
In the Application Navigator, right-click the Model node and select New from the context menu.
-
In the New Gallery select the All Features tab, then select Business Tier > EJB as the category and double-click the Entities from Tables item.
-
In Select EJB Version, select EJB 3.0 -- JPA Entities as the EJB version if not already selected, then Next.
Click Next to skip the persistence unit definition.
EJB 3.0 greatly simplifies entity beans and standardizes the POJO persistence model. Read more... Entity beans are concrete Java classes and do not require any interfaces. The entity bean classes support polymorphism and inheritance. Entities can have different types of relationships, and container-managed relationships are refined manually by the developer. -
In the Type of Connection page choose the Online Database Connection option. Then click Next.
-
In the Database Connection Details page, click the Create button to create a new connection.
-
Provide the following values to create the database connection to the hr schema. Note that the values provided here as examples may need to be modified to work with your environment. Leave the rest of the properies at their default.
Option Value Connection Name HR Username/Password hr / <your hr password> Save Password Checkbox checked Driver Thin Host Name The machine where the schema is installed (e.g. localhost) SID The database where the HR schema is installed (XE, orcl...)
Click Test Connection to confirm that you can connect.
Click OK if the connection was successful. Read more...
If the connection fails, check that the parameters entered are correct and that the Oracle database and listener services are running.
The connection should also appear in the Initialize Business Components Project page.-
Back in the Database Connection Details page, click Next.
-
In the Select Tables page, click Query to retrieve the available objects for the HR schema. Then select DEPARTMENTS and EMPLOYEES and shuttle the selection into the Selected pane using the right arrow button .
Click Next.
-
In this step, make sure the package name is oracle.model.
Click Next, then Finish.
-
In the Application Navigator one java class file is created for Departments and one for Employees.
-
Click the Save All icon to save your work.
An EJB diagram is a way to create and visualize entities, java beans and relationships between these components. To create an EJB diagram perform the following steps:
-
Right click the Model node in the Application Navigator and select New.
-
In the New Gallery select Business Tier > EJB as the category and double click EJB Diagram (JPA/EJB 3.0).
-
In the Create EJB Diagram dialog, change the default name for the diagram (EJB Diagram1) to HR EJB Diagram.The default Package name should be oracle.model.
Click OK.
-
On the Associate Diagram With Persistence Unit dialog, click OK to accept the proposed Persistence Unit (Model.jpr).
-
A new empty diagram opens in the diagram editor.
bModeling EJB/JPA components on a diagram can be useful for the developer. Read more... Enterprise JavaBeans (EJBs) modeling helps you visualize your EJB entity relationships and architecture, and to quickly create a set of beans to populate with properties and methods, and to create a graphical representation of those beans and the relationships and references between them. Whenever a bean is modeled, the underlying implementation files are also created. -
Select the Departments and Employees entities from the Application Navigator and then drag and drop them onto the diagram.
-
The diagram displays the EJB components that you just created from the Departments and Employees tables. Zoom in if necessary and reorganize the layout of the diagram to have both entities horizontally aligned. You can tidy the diagram by selecting relationships and using the Straighten lines option from the context menu.
-
Click the Save All icon to save your work.
As a result, dependencies and communication between clients and EJBs are reduced. If you are performing remote access without a session facade, numerous remote calls are needed for the clients to access EJB 3.0 entities directly over the network. This results in a large amount of network traffic that negatively affects performance. In addition, without a facade the client depends directly on the implementation of the business objects, so that if the interface of an EJB changes, client objects have to be changed as well.
In this step, you create a session bean that implements a method to find employees and departments records.
-
In the Component Palette, select the EJB Components library and open the EJB Nodes.
-
Select the Session Bean component and then drag and drop it onto the diagram.
The Create Session Bean Wizard opens. (If necessary, click Next on the Welcome step.)
-
In the EJB Name and Options step, set the EJB Name to HRFacade and make sure that the following values are properly set:
Property Value EJB Name HRFacade Session Type Stateless Transaction Type Container Generate Session Facade Method (Checked) Entity Implementation JPA Entities Persistence Unit Model
Click Next.
There are two types of session bean, Stateful and Stateless. Read more...
A stateful session bean maintains conversational state on behalf of the client. A conversational state is defined as the session bean field values plus all objects reachable from the session bean fields. Stateful session beans do not directly represent data in a persistent data store, but they access and update data on behalf of the client. The lifetime of a stateful session bean is typically that of its client.
Stateless session beans are designed strictly to provide server-side behavior. They are anonymous because they contain no user-specific data. The EJB architecture provides ways for a single stateless session bean to serve the needs of many clients. All stateless session bean instances are equivalent when they are not involved in serving a client-invoked method. The term stateless means that it does not have any state information for a specific client. However, stateless session beans can have non-client specific state, for example, an open database connection.
Use Container for a transaction being handled by the session facade and bean for managing user transaction explicitly through a programmatic process. -
In the Session Facade step, any entities in this project appear as a node in the tree control. You can select the checkbox to include all entity methods this entity exposes, or expand the nodes and select a subset of methods.
Expand the Employees and Departments nodes and select all methods for each entity.Click Next.
-
In the Class Definition step, make sure that the full name for Bean Class is oracle.model.HRFacadeBean, and then click Next.
-
In the following step, ensure that both Remote and Local interface implementations are selected. The remote interface is used for client applications that run in a separate virtual machine, such as Java clients, whereas a local interface is used for client applications that run in the same virtual machine, such as Web clients.
Click Next to review the summary of the created classes and then Finish.
The diagram should now look like the following:
-
The Application Navigator should look like this:
The session bean is made up of three files: HRFacadeBean - contains the session bean code. HRFacade - describes the capabilities of the bean for remote clients and HRFacadeLocal describes the capabilities for the local client.
Click the Save All icon to save your work.
You now expose the EJB as a data control for the Oracle ADF framework. This simplifies the way that you bind user interfaces to the EJB. To learn more about the ADF Framework visit: http://oracle.com/technology/products/adf
To create ADF data controls from EJB Session Beans, perform the following steps:
-
Right-click the HRFacadeBean node in the Application Navigator and select Create Data Control from the context menu.
-
In the Choose EJB Interface dialog, select Local, and click OK.
Click the Save All icon to save your work.
-
The Application Navigator should now look like this:
A number of things happen in your project when you create a data control. Read more...
When you create a data control based on an EJB session bean, JDeveloper creates the data control definition file (DataControls.dcx), opens the file in the overview editor, and displays the file's hierarchy in the Data Controls panel. This file enables the data control to work directly with the service and the bindings. Expand the Data Controls accordion to review the components that have been created and are now available for the UI.
-
Notice the Data Control Registry displaying the available data controls.
Expand the HRFacadeLocal node. Selecting the departmentsFindAll node provides details in the right hand side about the data control.
The overview editor for the DataControls.dcx file provides a view of the master-detail hierarchies of your data model as well as methods from the session facade. Read more...
When you select a node, you can view the bean properties for the corresponding entity class in the Attributes tab. In the Accessors tab, you can view all bean properties for the corresponding entity class that return a collection. In the Operations tab, you can view other methods from the session facade that operate on the entities.-
You can collapse the Model project node and right-click any of the tabs to close all open tabs.