Part 1: Build the Data Model

You can easily install the schema and connect to the database, and then create an application and projects in which to organize your application files. Then work in JDeveloper's IDE to create the business services for your application.

Install the Schema: Download the schema zip file from OTN and install it. The cue cards use tables that are part of the Fusion Order Demo (FOD) schema.

Create a New Application and Project: Use the Create Application wizard to create an application and projects for the EJB Components model and the user interface portions of the application.

Create a Database Connection: Use the Create Database Connection dialog to create a connection to the schema.

Create Entities from Tables: Use the Create Entities from Tables wizard to create JPA entities.

Create an EJB Diagram: Use the Create EJB Diagram dialog then drag and drop tables onto the diagram.

Create a Session Bean: Use the Component Palette to launch the Create Session Bean wizard.

Add a Named Query: Double-click the entity in the diagram to open it in the source editor and add sample code.

Create and Run a Sample Java Client: Use the Create Sample Java Client dialog to create the file, and then edit it in the source editor.

Run the Java Service Outside the Java EE Container: Use the Create Persistence Unit dialog opened from the Create Java Service Facade wizard to create a persistence unit that runs outside the Java EE container.

Expose the EJB as a Data Control: In the Application Navigator, create the data control from FODFacadeBean.java.

 

Install the Schema

tell me more icon Installing the Schema

The steps and examples in the cue cards are based on tables that are part of the Fusion Order Demo (FOD) schema. This schema is also used as the database for the sample application that ships with Oracle JDeveloper 11g, as well as other collateral in this release. It will be convenient to have this schema installed, and you only need to do it once. If you have already installed the FOD schema, you can skip this step and go directly to the next card.   [ tell me more...]





  1. go to OTN Download the schema zip file from OTN. If you created the schema previously, go to the cue cards icon next cue card.
  2. Unzip the file to a convenient location (for example, c:\temp).
  3. From the File menu, choose Open . Open the workspace c:\temp\Infrastructure\Infrastructure.jws.
  4. If you are prompted to migrate the project, click Yes to confirm, then click OK.
  5. In the Application Navigator, expand the MasterBuildScript project. Under Resources double-click build.properties to open it in the editor.
  6. Set the appropriate values in the build.properties file ( jdeveloper.home, and all the jdbc.* and db.* settings). Keep all other properties set to their default values. The demo user must be named FOD.
    The relevant settings are:
    jdeveloper.home             The /jdeveloper directory where you have JDeveloper installed, for example, c:/JDeveloper_11/jdeveloper/
    jdbc.urlBase                    Base URL for your database, for example, jdbc:oracle:thin:@localhost
    jdbc.port                         Port number for your database, for example, 1521
    jdbc.sid                           Database System Identifier, for example, XE or ORCL
    db.adminUser                  Database user with admin privileges, for example, system
    db.demoUser.tablespace  Tablespace name where the FOD user will be installed, for example, USERS
  7. In the MasterBuildScript project, select the build.xml file.
  8. In the Structure window, right-click the refreshSchema target and choose Run Target "refreshSchema" .
  9. When prompted, enter the password for the database user with admin privileges.

    tell me more icon In the IDE

    After running the Ant task, you should see a build successful message in the JDeveloper Log window.   [ tell me more...]



 

Create a New Application and Project

tell me more icon Creating a New Application and Project

The JDeveloper application is the highest level in the organizational structure. It stores information about the objects you are working with, while you are creating your application. It keeps track of your projects and the environment settings while you are developing.   [ tell me more...]





  1. Open the Create Application wizard [ File > New > General > Applications > Application] .
  2. Enter the application name OrdersApplication to follow along with the example.
  3. In the A pplication Package Prefix field, enter oracle.
  4. Select Java EE Web Application from the Applica tion Template list, and click Next .

    tell me more icon Application Templates

    Application templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of technologies already specified. The new application created from the template appears in the Application Navigator already partitioned into tiered projects, with the associated technology scopes set in each project.   [ tell me more...]



  5. On step 2, enter UserInterface as the name for the view and controller project, and click Next twice.
  6. On step 4, enter EJBModel as the name for the model project, and click Finish .
  7. In the Application Navigator, expand the Application Resources panel to see where resources for this application are displayed.

    tell me more icon In the IDE

    In the Application Navigator, projects are displayed as the top level in the hierarchy. The Application Navigator should now look like this:   [ tell me more...]



 

Create a Database Connection

tell me more icon Creating a Database Connection

You can connect to any database for which you have connection details, or install the sample schema used in the cue card examples and then establish a connection to it. If you installed the sample schema, you will be able to follow the steps in the cue cards exactly as written. If you work with your own database, you can supply your own values as needed.   [ tell me more...]





  1. Open the Create Database Connection dialog [ File > New > General > Connections > Database Connection] .
  2. Select Application Resources if it is not selected as the Create Connection In option.
  3. Enter a name for the connection, select the connection type, and enter the username and password. To follow along with this example, use FOD for the connection name and  fod for the username.
  4. Click Test Connection to confirm that you can connect.
  5. Click OK if the connection was successful.
  6. In the Application Navigator, expand the Connections and Database nodes in the Application Resources panel to see the database objects.

    tell me more icon In the IDE

    The database connection is now included as a resource for your application.   [ tell me more...]



 

Create Entities from Tables

tell me more icon Creating Entities from Tables

Enterprise JavaBeans (EJB) technology is the server-side component architecture for Java Platform, Enterprise Edition (Java EE) that encapsulates business logic. EJB technology enables rapid and simplified development of distributed, transactional, secure and portable applications based on Java technology.  [ tell me more...]





  1. In the Application Navigator, select the EJBModel project you just created and launch the Create Entities from Tables wizard [ File > New > Business Tier > EJB > Entities from Tables] .
  2. On step 2, click Next to let the wizard create a default persistence unit definition.
  3. On step 3, confirm that Online Database Connection is selected and click Next .
  4. On step 4, confirm that FOD is the selected database connection and click Next .

    tell me more icon Connecting to a Database

    The database connection you made earlier is available as an application resource, and can be selected from the Connection dropdown list, if it is not selected by default.  [ tell me more...]



  5. On step 5, click Query to populate the A vailable list.

    tell me more icon Querying the Database and Selecting Tables

    In the wizard page, you can click Query to query the database and list all the available tables. From the list of tables, you can select the tables you want to work with in your application. In this example, you will select the ORDERS and ORDER_ITEMS tables.  [ tell me more...]



  6. Select two tables, ORDERS and ORDER_ITEMS from the A vailable list and shuttle shuttle them to the Selec ted list. Then click Next .
  7. On step 6, accept the default package name. Make sure that Fiel ds and Implement java.io. Serializable are selected, and java.util.List is selected from the Collection Type for Relationship Fields dropdown. Then click Next
  8. On step 7, accept the default values and click Finish .
  9. Click save all Save All to save your work.

    tell me more icon In the IDE

    In the Application Navigator, one Java file is created for Orders and one for OrderItems, in the Application Sources node. These are the JPA entities that were created from the Orders and Order_Items tables.   [ tell me more...]



 

Create an EJB Diagram

tell me more icon Creating an EJB Diagram

You can model Enterprise JavaBeans on a diagram to visualize a design as you develop it. Whenever a bean is modeled, the underlying implementation files are also created.  [ tell me more...]





  1. In the Application Navigator, select the EJBModel project and open the Create EJB Diagram dialog [ File > New > Business Tier > EJB > EJB Diagram] .
  2. Enter EJB Diagram as the diagram name, and accept the default package name. Then click OK.
  3. Click OK to associate the diagram with the EJBModel (EJBModel.jpr) persistence unit.

    tell me more icon Adding Objects to the Diagram

    The EJB diagram created with the dialog is opened in the editor area.   [ tell me more...]



  4. In the Application Navigator, select the Orders and OrderItems entities, then drag and drop them onto the EJB diagram.
  5. Click save all Save All to save your work.

    tell me more icon In the IDE

    The diagram displays the EJB components that correspond to the reverse engineering action you performed on Orders and OrderItems. The Orders and OrderItems entities are displayed along with a representation of their relationship.   [ tell me more...]



 

Create a Session Bean

tell me more icon Creating a Session Bean

A session facade presents client objects with a unified interface to the underlying EJBs. The client interacts only with the facade, which resides on the server and invokes the appropriate EJB methods. 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.  [ tell me more...]





  1. In the Component Palette, EJB Components page, EJB Nodes panel, select the session bean Session Bean component then drag and drop it onto the diagram.
  2. On step 2 of the Create Session Bean wizard that launches, enter FODFacade as the EJB name.
  3. Confirm that the following default options are set: Session Type: State less ; Transaction Type: Container ; Generate Session Facade Methods: selected; Entity Implementation: JPA Entities ; Persistence Unit: EJBModel (EJBModel.jpr) .
  4. Click Next twice, accepting the defaults for step 3.
  5. On step 4, accept the default name for the bean class, and click Next .
  6. On step 5, confirm that both Implement a Remote Interface and Imp lement a Local Interface are selected. Accept the default names of the interfaces. Then click Next .

    tell me more icon Using a Local or Remote Interface

    Clients access an EJB component through its interface. The remote interface is used for client applications that run in a separate virtual machine, such as Java clients. The local interface is used for client applications that run in the same virtual machine, such as web clients.  [ tell me more...]



  7. Review the summary of created classes, then click Finish .

    tell me more icon In the IDE

    The EJB diagram now includes the session bean you just created.  [ tell me more...]



 

Add a Named Query

tell me more icon Adding a Named Query

Named queries enable you to define queries at design time and then use them at run time. A NamedQuery metadata statement has been created by default in the OrderItems.java entity, by the Create Entities from Tables wizard. It retrieves all rows from the OrderItems table:  [ tell me more...]





  1. In the EJB diagram, double-click the OrderItems entity bean to open it in the source editor.

    tell me more icon Editing Source Code

    Features available to you in the source editor include:   [ tell me more...]



  2. Expand @annotations and add a query to the class that retrieves order items by quantity.
    code sample icon Use sample code
  3. Click make icon Make to compile the OrderItems.java class. You should see a Successful compilation message in the Messages Log window.
  4. To add the new method to the session bean, in the Application Navigator, right-click the FODFacadeBean.java node and choose Edit Session Facade .
  5. In the Specify Session Facade Options dialog, expand the OrderItems node and select public List <OrderItems> getOrderItemsfindByQuantity. Then click OK.

    tell me more icon In the IDE

    In the Specify Session Facade Options dialog, you can expose the new method by selecting it from the available nodes. All entities in this project appear as nodes in the tree.  [ tell me more...]



 

Create and Run a Sample Java Client

tell me more icon Creating and Running a Sample Java Client

JDeveloper includes a sample Java client utility you can use to test an EJB. To generate a sample Java client, you will right-click a session bean in the Application Navigator and choose New Sample Java Client .  [ tell me more...]





  1. In the Application Navigator, right-click FODFacadeBean.java and choose New Sample Java Client .
  2. Confirm that the client class name is oracle.model.FODFacadeClient.
  3. Make sure IntegratedWebLogicServer is selected in the Appli cation Server Connection dropdown list, then click OK.
  4. In the FODFacadeClient class, add a value parameter 3 to the FindByQuantity method: (List<OrderItems>)fODFacade.getOrderItemsFindByQuantity( 3)) .
  5. Click save all Save All to save your work.
  6. In the Application Navigator, right-click FODFacadeBean.java and choose R un to launch the facade bean in Integrated WebLogic Server.
  7. Once the default server instance has started, right-click FODFacadeClient.java and choose R un .

    tell me more icon Running the Sample Client

    To test your business services, you will right-click the session bean in the Application Navigator and choose R un . JDeveloper automatically starts Integrated WebLogic Server, if it is not already running. Then JDeveloper compiles and deploys the application to Integrated WebLogic Server:  [ tell me more...]



  8. In the FODFacadeClient.java class, comment out the for loop corresponding to the getOrderItemsFindAll method, and comment out the for loop corresponding to the getOrdersFindAll method, to see only the results of the getOrderItemsFindByQuantity method.

    tell me more icon Editing the Class

    To better visualize the result of the getOrderItemsFindByQuantity method, you can edit the FODFacadeClient.java class, and comment out:  [ tell me more...]



  9. Click make Make to recompile the class.
  10. Right-click FODFacadeClient.java and choose R un .

    tell me more icon In the IDE

    After editing the code and running the sample client again, the Log window should display only the returned rows retrieved by the '3' clause (that is, order items with quantity greater than 3):  [ tell me more...]



 

Run the Java Service Outside the Java EE Container

tell me more icon Running the Java Service Outside the Java EE Container

A persistence unit can be configured to run inside or outside the container. In EJB 3.0, you can run entities in a pure Java SE environment, without using an application server. One reason you might do this is to create a simple Java SE test bed (using JUnit, perhaps) to test your entity behavior without the overhead of deploying/executing in an application server. Another reason would be to run a Swing application locally.  [ tell me more...]





  1. In the Application Navigator, right-click persistence.xml and choose New Java Service Facade .
  2. Accept the default service class name, and confirm that Generate a main() method with sample client code is selected. Then click Next to create a new persistence unit.
  3. On step 2, enter outside as the persistence unit name. Confirm that JDBC Connection is selected and the database connection you created is shown in the dropdown list (for example, FOD) and click Next . Then click Finish .

    tell me more icon Creating a Java Service Facade

    From within the Create Java Service Facade wizard, you can create a new persistence unit for use either inside or outside a Java EE container.   [ tell me more...]



  4. Edit the JavaServiceFacade.java file in the source editor to add a new line to the class to retrieve order items by quantity and get the quantity.
    code sample icon Use sample code
  5. Click make Make to compile the JavaServiceFacade class.
  6. In the Application Navigator, right-click JavaServiceFacade.java and choose R un .

    tell me more icon Running a Java Service Facade

    When the Java service facade runs, the Log window displays the result of the execution of the class running outside the Java EE container, returning the quantity values that are greater than 3 in the retrieved records:  [ tell me more...]



  7. In the Application Navigator, double-click persistence.xml to view the content of the file.

    tell me more icon In the IDE

    When you double-click persistence.xml in the Application Navigator, the file opens in the default editor. Click Overview to view the file in the overview editor for the JPA Persistence Descriptor.   [ tell me more...]



 

Expose the EJB as a Data Control

tell me more icon Exposing the EJB as a Data Control

After creating the data model, you can expose the EJB as a data control for the Oracle ADF framework. This simplifies the binding of the user interface to the EJB.   [ tell me more...]





  1. In the Application Navigator, right-click FODFacadeBean.java and choose Crea te Data Control .
  2. In the Choose EJB Interface dialog, select Local , and click OK.

    tell me more icon Choosing an EJB Interface

    The local interface is used for clients that run in the same virtual machine, such as web clients. You will be building web pages for this application, so Local is the appropriate selection.   [ tell me more...]



  3. Click save all Save All to save your work.
  4. In the Application Navigator, expand the Data Controls panel.
  5. Collapse the EJBModel project node and close all open files before continuing.

    tell me more icon In the IDE

    The root node of the Data Controls panel represents the data control registered for the business service. While the data control itself is not an item you can select, you may select among the operations it supports.   [ tell me more...]



 

cue cards iconNext step

 

Copyright © 1997, 2009, Oracle. All rights reserved.

false ,,,,,,,,,,,,,,,