Previous Next vertical dots separating previous/next from contents/index/pdf

8. Managing persistent entities with Entities Editor

BEA Workshop Studio allows you to view, create, and manage Hibernate entity relationships. The Entities Editor provides a centralized view of all entity relationships, allows for modification of entity properties, and simple navigation between the object model, Hibernate mapping, and database schema layers.

8.1. View entity relationship diagram using the Entities Editor and review features of editor

As described previously, the Entities Editor displays relationships diagram for entities defined in the project.

  1. Expand the Hibernate Configuration branch in AppXplorer. Workshop provides a list of entities under the Entities branch based on the entities defined in the Hibernate configurations file.

  2. Double-click on Hibernate Configuration > Entities Editor to access all of the entities and their properties.

  3. The Hibernate Entities Editor displays all entity relationships defined in the web application. Each box displays a specific entity, its properties, and an icon denoting the nature of the relationship.
  4. The Hibernate Entities Editor provides an opportunity to perform various UI operations like Zoom In, Zoom Out, and Auto Arrangement of diagram. Right-click on the Entities Editor and select any action to perform from the pop-up menu.

  5. The Hibernate Entities Editor displays a list of properties for an entity or property of an entity with tool-tip.

  6. The Hibernate Entities Editor also provides facility to filter relationships between entities. This is very helpful feature to understand / review the entity relationship diagram when it is complex.

  7. Click the Filter button and select the options Many to One and One to Many to filter these relations between entities.

  8. Reset the filters.
  9. You can also review entities using AppXRay. Right-click the Product entity under the Hibernate Configuration Entities and select Show AppXRay Dependencies.

  10. It opens AppXaminer View showing the dependency diagram.

8.2. Edit the properties of Hibernate Persistent Entities using the Smart Editor

Using the Smart Editor in Properties view, Workshop provides an easy editing facility for standard properties of some objects.

  1. Select a Product entity in Hibernate Entities Editor, the Smart Editor displays the properties as defined in the Hibernate mapping file for the Product entity i.e. Product.hbm.xml.

  2. For each selected entity, you can edit the associated Java Bean class, strategy for persistence, and the database access information. To edit any information, either enter in text box or click on the icon to get a list of possible options.

  3. In Hibernate Entities Editor select the name property of Product entity. The Smart Editor displays properties of the name property. Observe the properties.

  4. In Smart Editor perform following changes to modify the Length property of property name.
  5. Press CTRL+S to save the changes.
  6. Open the hibernate mapping file Product.hbm.xml available under the com.bean.beans package and verify that the changes in name property of Product entity are reflected in hibernate mapping file Product.hbm.xml.

  7. As described earlier, the Smart Editor provides a facility to edit standard set of properties of the object. You can also view (and edit) an entire set of properties of an object by switching to the Properties Sheet editor.

8.3. Adding new properties to Customer and Contact entities

In addition to providing a view of the entity relationships for a project, and a simple mechanism to update configuration of existing entities, the Hibernate Entities Editor provides wizards to assist in defining new properties for a specific entity.

In this step, we will define a new One-to-Many Bi-directional Association between Customer and Contact entities.

we will add a New Property of type Customer in Contact entity and a New Set Property in Customer entity to hold collection of Contacts. This way we can define One-to-Many Bi-directional Association between Customer and Contact entities.

  1. In Hibernate Entities Editor right-click on Contact entity and select New Many-to-one... to add a new property for Contact entity to define many-to-one relation between Contact and Customer.

  2. In Many to One Tag dialog enter the property name customer, select the com.bea.beans.Customer Java class and the database column CUSTOMERID from the CONTACT table as shown below and click OK.

  3. Workshop will add the new code to the mapping file Contact.hbm.xml and update the Entities Editor to reflect the new content. You can observe a Uni-directional Many-to-One Association being defined between Contact and Customer entities.

  4. Press CTRL+S to save the changes.
  5. Right-click on Customer entity and select New Set... to add a new java.util.Set property for Customer entity. The Set property will maintain a list of contacts for the customer.

  6. In Collection Mapping wizard specify the collection property name contacts and other configuration parameters as shown below and click Next.

  7. Specify the collection property name contacts and select the entity class com.bea.beans.Contact that is being collected by the collection. Also, select the CUSTOMERID column of CONTACT table to specify the joining column with CUSTOMER table.

  8. Click Finish
  9. Workshop will add the new code to the mapping file Customer.hbm.xml and update the Entities Editor to reflect the new content. You can observe a Bi-directional Many-to-One Association being defined between Contact and Customer entities.

  10. Press CTRL+S to save the changes.
  11. Workshop displays 2 warnings in Problems view. The reason is that we have added properties and defined mappings in Customer.hbm.xml and Contact.hbm.xml files but not defined corresponding properties in source code.

  12. In Hibernate Entities Editor, right-click the Contact entity and select Open Java Source. It opens the com.bea.beans.Contact.java file. You can also double-click to open the Contact.java file.

  13. In Contact class add a property customer of type Customer and the corresponding getter/setter methods.
    private Customer customer;

    public Customer getCustomer( ) {
      return customer;
    }

    public void setCustomer(Customer customer) {
      this.customer = customer;
    }
  14. Save the Contact class.
  15. You can also open the Java Source file by double-clicking the entity in Hibernate Entities Editor. In Hibernate Entities Editor, double-click the Customer entity to open the com.bea.beans.Customer.java file. In Customer class add a property contacts of type java.util.Set and the corresponding getter/setter methods.
    private Set contacts;

    public void setContacts(Set contacts) {
      this.contacts = contacts;
    }

    public Set getContacts( ) {
      return contacts;
    }
  16. Save the Customer class.
  17. Verify that the warnings are cleared.

8.4. Navigate to specific mapping definitions

We have observed the capabilities of Hibernate Entities Editor for displaying and managing the entities. In this step, we will learn how to navigate to the specific mapping definitions. We will also review the Hibernate Mapping Editor and understand validation and code completion facility provided by the editor.

  1. In Hibernate Entities Editor right click the OrderData entity and select Open Mapping Source to navigate to the Hibernate mapping file for that entity.

  2. Workshop Studio provides Hibernate Mapping Editor - a combination of form and source editor for the Hibernate mapping configuration file which organizes mapping properties, provides forms to manage current properties, and includes wizards to assist in the creation of new content.

  3. In Editor the hyperlink for Java Class navigates to the Java Bean and the hyperlink for database Schema (if schema is defined) or Table navigates to that component in DbXaminer.
  4. If you select any property in Hibernate Mapping form editor, the corresponding code will be highlighted in the source editor.

  5. While managing the entity relationships, AppXRay analyzes the dependencies between the related ORM layers and provides validation and code completion (CTRL+SPACE). In source configuration, change the value of the name attribute of the many-to-one element to customer_NEW.

  6. It displays a WARNING icon with message stating the field customer_NEW is not defined in OrderData entity. Reset the value of name attribute of many-to-one element to customer. Save the mapping file.
  7. Move the cursor to name attribute of column element (under the many-to-one element) and press CTRL+SPACE. The code completion feature of AppXRay displays the available columns as defined in database table.

Click one of the following arrows to navigate through the tutorial:

 

Skip navigation bar   Back to Top