Skip Headers
Oracle® Fusion Middleware User's Guide for Oracle JDeveloper
11g Release 2 (11.1.2.2.0)

Part Number E17455-03
Go to Documentation Home
Home
Go to Table of Contents
Contents
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

23 Developing Java EE and Java Applications Using Modeling

This chapter describes how to work with Java EE and Java application diagrams using the latest modeling tools and technologies included in Oracle JDeveloper.

This chapter includes the following sections:

23.1 About Developing Java EE and Java Applications Using Modeling

Oracle JDeveloper provides you with a wide range of diagramming tools to model your Java EE and Java applications systems.

23.2 Business Component Diagram

Use the business component diagram to visualize and organize the business entities and objects in your enterprise application.

For more information see, “Creating an Entity Diagram for Your Business Layer” in the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

23.3 Modeling EJB/JPA Components on a Diagram

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.

To model EJBs start by creating an EJB diagram. For more information, see "To create a new diagram:". You can later add other elements like UML classes, Java classes, business components, offline database tables, UML use cases and web services to the same diagram. For more information, see "How to Work with Diagram Elements".

About Entity, Session and Message-Driven Beans

Enterprise JavaBeans are created on a diagram by using the Entity Bean icon, Session Bean icon or Message-Driven Bean icon on the EJB Component Palette for the diagram, and then clicking on the diagram where you want to create the element. The implementation files for the modeled elements are created in the location specified by your project settings.

Tip:

If you want to model the implementing Java classes for a modeled bean on a diagram, right-click the modeled bean and choose Show Implementation Files.

Properties and methods are added by either double-clicking the bean and adding the property or method using the EJB Module Editor or by creating the new property or method 'in-place' on the modeled bean itself. For more information, see Section 23.3.5, "Modeling Properties and Methods".

Relationships Between Beans

References can be created from any bean to any other bean with a remote interface using the EJB Reference icon and local references can be created from any bean to any other bean with a local interface using the EJB Local Reference icon on the EJB Component Palette for the diagram. For more information, see Section 23.3.6, "How to Model Cross Component References".

A variety of relationships can be created quickly between modeled entity beans using the 1 to * Relationship icon, Directed 1 to 1 Relationship icon, Directed 1 to * Relationship and Directed Strong Aggregation icons on the EJB Component Palette for the diagram. For more information, see Section 23.3.3, "How to Model a JPA Relationship".

Note:

If you change, add to, or delete from, the implementation files for anything that is displayed on a diagram, those changes will be reflected on modeled representations of those elements. Conversely, any changes to the modeled Enterprise JavaBeans are also made to the underlying implementation files.

You can annotate a diagram of Enterprise JavaBeans using notes, dependency relationships and URL links.

23.3.1 Creating a Diagram of EJB/JPA Components

The relationships between entity, session, and message-driven beans, and their properties and methods, can all be modeled graphically on an EJB diagram. EJB diagrams are also used for modeling UML classes, Java classes, UML use cases, offline database objects, business components and web services.

To create a diagram of Java classes:

  1. Create a new EJB diagram in a project or application in the New Gallery.

  2. Create the elements for the diagram using the EJB Component Palette. Table 23-1 shows the EJB Component Palette.

    Table 23-1 EJB Component Palette Icons

    Drop-down List Icon Name

    EJB Nodes

    Entity

    Entity

     

    Message-driven Bean

    Message-driven Bean

     

    Session Bean

    Session Bean

    Entity Relationships

    Bidirectional * to * Relationship

    Bidirectional * to * Relationship

     

    Bidirectional * to 1 Relationship

    Bidirectional * to 1 Relationship

     

    Bidirectional 1 to 1 Relationship

    Bidirectional 1 to 1 Relationship

     

    Unidirectional * to * Relationship

    Unidirectional * to * Relationship

     

    Unidirectional * to 1 Relationship

    Unidirectional * to 1 Relationship

     

    Unidirectional 1 to * Relationship

    Unidirectional 1 to * Relationship

     

    Unidirectional 1 to 1 Relationship

    Unidirectional 1 to 1 Relationship

    EJB Edges

    Entity Inheritence Edge

    Entity Inheritence Edge

     

    Session Facade Edge

    Session Facade Edge

    Diagram Annotations

    Attachment

    Attachment

     

    Group

    Group

     

    Link

    Link

     

    Note

    Note


You can annotate your diagram by attaching notes to diagram elements. For more information, see Chapter 22, "How to Work with Diagram Annotations."

23.3.2 How to Read an EJB/JPA Components Diagram

You can model session, entity and message-driven beans in JDeveloper. Modeled session and entity beans are made up of several compartments. For example, Message-driven beans have only a name compartment containing the «message-driven bean» stereotype and the name of the bean. For EJB 3.0 beans the model looks different because there are no compartments for interfaces.

Figure 23-1 EJB/JPA Components Diagram

EJB/JPA Components Diagram

Notice the relationship and connectors between the beans. References can be created from any bean to any other bean with a remote or local interface. References can only be modeled between beans that are inside the current deployment descriptor.

23.3.3 How to Model a JPA Relationship

You can model a relationship between any two entities on a class diagram by dragging the relationship component from the palette. You can also show the inheritance edge between the root and child entity. The entity at each end of a relationship must have container-managed persistence and a local interface.

To model a relationship between two entities on a diagram:

  1. Click the icon for the relationship you want to create, from those listed on the EJB Component Palette.

    Notes:

    The navigability and multiplicity of a relationship end can be changed after it has been created.If these icons are not displayed, select EJB Components from the dropdown on the Component Palette.

  2. Click the entity at the 'owning', or 'from', end of the relationship.

    Note:

    If you want to represent this relationship using a container-managed relationship (CMR) field, this is the bean in which the field will be created.

  3. Click the entity bean at the 'to' end of the relationship.

  4. Click the relationship line on the diagram, then click the text fields adjacent to the association to enter the relationship name.

    Note:

    To change the multiplicity of a relationship end on the diagram, right-click on the relationship end and choose either Multiplicity > 1 or Multiplicity > *.

23.3.4 How to Model an EJB/JPA Component On a Diagram

Entity, session, and message-driven beans can be modeled using the diagram features in JDeveloper. Properties and methods can also be modeled.

  • Entity beans can be either Container-Managed Persistence (CMP) or Bean-Managed Persistence (BMP). Before creating entity beans with bean-managed persistence, you may want to first consider whether you will need to create relationships between those entity beans. Relationships can only be created between entity beans with container-managed persistence.

  • Session beans can be have their session type changed on a class diagram by right-clicking on the session bean and choosing Session Type, then Stateful or Session Type, then Stateless.

  • Message-driven beans are most often used to interact (using EJB References) with session and entity beans.

23.3.5 Modeling Properties and Methods

Properties and methods can be added to modeled EJBs by either double-clicking the bean and adding the property or method using the EJB Module Editor or by creating the new property or method directly on the modeled bean.

23.3.5.1 Creating Properties on Modeled Beans

When creating a property directly on a modeled bean, enter the name and datatype of the property. For example:

name : java.lang.String

A public (+) visibility symbol is automatically added to the start of the property.

Note:

If a property type from the java.lang package is entered without a package prefix, for example, String or Long, a property type prefix of java.lang. is automatically added. If no type is given for a property, a default type of 'String' (java.lang.String) is used

23.3.5.2 Creating Methods on Modeled Beans

Both local/remote and local/local home methods can be created on modeled beans on a class diagram. Modeling a method on a bean also creates the corresponding code in the implementing Java class.

When creating a method in-place on a modeled bean, enter the name, and optionally the parameter types and names, and return type of the method. The method return type must be preceded by a colon (:). For example:

getName(String CustNumber) : java.lang.String

A public (+) visibility symbol is automatically added to the start of the method.

Notes:

If a return type from the java.lang package is entered without a package prefix, for example, String or Long, a return type prefix of java.lang. is automatically added to the Java in the method's class. If no parameter types are provided, the method will be defined with no parameters. If no return type is specified, a default return type of void is used. To change a property of the method, double-click the class on the diagram, or on the Navigator pane, then change the details of the method using the EJB Editor.

23.3.6 How to Model Cross Component References

References can be created between modeled beans on a class diagram.

  • EJB References can be created from any bean to any other bean with a remote interface.

  • EJB Local References can be created from any bean to any other bean with a local interface.

Note:

References can only be made to beans that are inside the current deployment descriptor.

To model a reference between modeled beans:

  1. Click the icon for the reference you want to create, from those listed on the EJB Component Palette:

    • EJB Reference

    • EJB Local Reference

    Note:

    If these icons are not displayed, select EJB from the list on the Component Palette.

  2. Click the bean at the 'owning', or 'from', end of the reference.

  3. Click the bean at the 'to' end of the reference.

23.3.7 How to Display the Implementing Source Code for a Modeled Bean

Each modeled bean has underlying Java source files that contain the implementation code for that element. These implementation files can be displayed on the diagram as modeled Java classes.

To display a modeled implementing Java class for a modeled bean:

  • Select the bean, the Java implementation of which you want to model on the diagram, then choose Model, then Show, then Implementation Files.

  • Or, right-click the bean on the diagram, the Java implementation of which you want to model on the diagram, then choose Show Implementation, then Files.

23.3.8 How to Display the Source Code for a Modeled Bean

The Java source code for a modeled bean can be displayed in the source editor with simple commands on the diagram.

To display the Java source code for a model element:

  • Right-click the element on the diagram. Choose Go to Source, then choose the source file you want to view.

  • Or, select the element on the diagram. Choose Model > Go to Source.

23.3.9 How to Change the Accessibility of a Property or Method

You can change the accessibility of a property or method on a modeled bean on a diagram with simple commands on a diagram.

To change the accessibility of a property or method:

  1. Right-click the property or method you want to change.

  2. Choose the required accessibility option from the Accessible from option on the context menu.

    The accessibility options are:

    • Local Interface

    • Remote Interface

    • Local and Remote Interfaces

23.3.10 How to Reverse-Engineer a JPA Entity on a Diagram

Modeled entity beans can be reverse-engineered on a diagram of EJBs from table definitions in your application database connection.

To reverse-engineer a table definition to an entity bean:

  1. Open, or create a diagram.

  2. Expand the node in the Connections Navigator for your database connection.

  3. Expand the user node, then the Tables nodes.

  4. Click the table, the definition to use to create an entity bean, and drag it to the current diagram.

    To reverse-engineer several tables to entity beans, hold down the Ctrl key, select the tables in the navigator and drag these tables to the diagram, then release the Ctrl key.

  5. Select the EJB version and click OK.

23.4 Java Class Diagram

Model your Java EE Java classes and class systems using the Java class diagram features. For more information see Chapter 22, "How to Work with Class Diagrams."

23.5 Database Diagram

Modeling your database structures gives you a visual view of your database schema and the relationships between the tables, stored in your online or offline database. You can also transform database tables to Java classes and interfaces and vice-versa using the transformation features. For more information on database transformation see Chapter 22, "Transforming Java Classes and Interfaces".

23.5.1 How to Work with the Database Modeling Features

With JDeveloper, you can model offline database objects as well as database objects from a live database connection. You can also create database objects such as tables and foreign key relationships right on your diagram and integrate them with an online or offline database.

Use database diagrams to view your business entity structure and relationships, as well as create directly on your diagram components such as tables and foreign key relationships, views and join objects, materialized views, synonyms and sequences.

All of the database objects from online or offline databases, as well as the new objects you create, are displayed in the Application Navigator.

23.5.1.1 Benefits of Database Modeling

Add or create offline and live online database objects using the Application Navigator and the Component Palette.

Use a database diagram to do the following:

  • Create and visualize tables and their columns.

  • Create and visualize foreign key relationships between tables.

  • Create and visualize views, materialized views, and materialized view logs.

  • Create and visualize sequences and synonyms.

In addition, you can create database objects on a diagram based on templates.

23.5.1.2 How to Get Started with Database Modeling

Create your database using the New Gallery. See "To create a new diagram:". Once you've created your database diagram, you can choose from the available components in the Component Palette, as shown in Figure 23-2.

Figure 23-2 Database Component Palette

database component palette

Create an offline database object on the diagram by clicking on the icon on the Database Objects Component Palette, and then clicking on the diagram where you want to create the object. You can also drag objects from a database connection in the Database Navigator, or from an offline schema in the Application Navigator, onto a diagram.

You can model online or offline tables on any type of diagram, (except an activity diagram), and you can add elements like UML classes, Java classes, business components, Enterprise JavaBeans, UML use cases, and web services on the same diagram.

You can create offline database objects on a diagram that are based on templates. The first time you add an object to a new database diagram, the Specify Location dialog appears, where you specify whether the objects are offline database objects in a project, or database objects in a database connection. If you want to create offline database objects based on templates, you can create a set of templates at the same time.

You can add the elements that define the object by either double-clicking the modeled object to display the appropriate edit dialog, or by creating the new element 'in-place' on the modeled object.

You can annotate a diagram of database objects using notes, dependency relationships, and URL links.

If you change, add to or delete from the definition of anything that's displayed on a diagram, those changes will be reflected on the modeled representations of those database objects. Conversely, any changes to the modeled database objects are also made to the underlying definitions.

Foreign keys

Foreign keys can be created quickly between modeled tables clicking Foreign Key on the Database Component Palette, then clicking the table you want to originate the foreign key, and then clicking the destination table for the foreign key. The Create Foreign Key dialog allows you to select an existing column in the target table, or create a new column.

Join Objects

You can create join objects between two table usages in a view by clicking (Join Objects) on the Database Component Palette, then clicking on the two table usages to be joined. The Edit Join dialog allows you to specify the join.

Materialized Views

Materialized Views are created on a diagram by clicking on (Materialized View) on the Database Component Palette, and then clicking on the diagram where you want to create the materialized view. You can also drag materialized views from a database connection defined in JDeveloper, or from an offline database in the Application Navigator, and drop them on the diagram.

Materialized Views from Template

Materialized Views based on templates are created on a diagram by clicking on (Materialized View from Template) on the Database Component Palette, and then clicking on the diagram where you want to create the materialized view. The Choose Template Object dialog is displayed, which allows you to choose the template you want to base the materialized view on.

Private and Public Synonyms

Synonyms are created on a diagram by clicking on (Synonym) on the Database Component Palette, and then clicking on the diagram where you want to create the synonym. You can also drag synonyms from a database connection defined in JDeveloper, or from an offline database in the Application Navigator, and drop them on the diagram.

Public synonyms are created in the PUBLIC schema.

Relation Usage

Define a base relation for a view by clicking on (Relation Usage) on the Database Component Palette, and then clicking on the view.

Sequences

Sequences are created on a diagram by clicking on (Sequence) on the Database Component Palette for the diagram, and then clicking on the diagram where you want to create the sequence. You can also drag sequences from a database connection defined in JDeveloper, or from an offline database in the Application Navigator, and drop them on the diagram.

Sequences from Templates

Sequences based on templates are created on a diagram by clicking on (Sequence from Template) on the Database Component Palette for the diagram, and then clicking on the diagram where you want to create the sequence. The Choose Template Object dialog is displayed, which allows you to choose the template you want to base the materialized view on.

Synonyms from Templates

Synonyms based on templates are created on a diagram by clicking on (Synonym from template) on the Database Component Palette for the diagram, and then clicking on the diagram where you want to create the synonym. The Choose Template Object dialog is displayed, which allows you to choose the template you want to base the materialized view on.

Tables

Tables are created on a diagram by clicking on (Table) on the Database Component Palette, and then clicking on the diagram where you want to create the table. You can also drag tables from a database connection defined in JDeveloper, or from an offline database in the Application Navigator, and drop them on the diagram.

You can choose to view table column icons on a modeled table which indicates which columns are primary keys, or foreign keys, or unique keys.

The first column in the modeled table indicates whether the column is in a primary, unique, or foreign key:

  • Column is in a primary key

  • Column is in a foreign key

  • Column is in a unique key

  • Column has a check constraint

The second column indicates whether the table column is mandatory.

Note:

If a table column is in a primary key it will only display the primary key icon even though it may also be in a unique key or foreign key.

Tables from Templates

Tables are created on a diagram by clicking on (Table from template) on the Database Component Palette, and then clicking on the diagram where you want to create the table. The Choose Template Object dialog is displayed, which allows you to choose the template you want to base the materialized view on.

Views

Views are created on a diagram by clicking on (View) on the Database Component Palette, and then clicking on the diagram where you want to create the view. You can also drag views from a database connection defined in JDeveloper, or from an offline database in the Application Navigator, and drop them on the diagram.

Define the view by adding tables and views, or table columns or elements of other views to the newly defined view. You can add the views by creating them from the Component Palette, by dragging other views and tables on the diagram onto the view, by dragging offline database objects from the Application Navigator, or by dragging database objects from a connection in the Database Navigator.

Views from Templates

Views are created on a diagram by clicking on (View from template) on the Database Component Palette, and then clicking on the diagram where you want to create the view. The Choose Template Object dialog is displayed, which allows you to choose the template you want to base the materialized view on.

23.5.1.3 How to Change the Database or Schema

  1. On the database diagram, right-click and choose Create Database Objects In > Database or Schema.

  2. Complete the Specify Location dialog (selecting Application Project for offline database objects, or Database Connection for database objects) or Select Offline Schema dialog.

Note:

All subsequent database objects will be created in the database or schema you have chosen. Existing objects are unchanged.