What Is an Entity Object?

Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents

Entity objects are classes that encapsulate the business model, including rules, data, relationships, and persistence behavior, for items that are used in your business application. For example, entity objects can represent

From an object-oriented perspective, an entity object represents an object in the real-world problem domain. From a relational database perspective, an entity object provides a Java representation of data from a database table. Advanced programmers can map entity objects to other types of data sources, such as spreadsheets, flat files, and XML files.

Depending on how you want to work, you can automatically create entity objects from existing database tables or define entity objects and use them to automatically create database tables.

Entity objects encapsulate business logic

The best place to write your business logic is in entity objects, because they consistently enforce business logic for all views of data, accessed through any type of client interface. Business logic includes the following items:

Business logic in an entity object provides immediate feedback to the user if changes are inappropriate. This way, the in-memory business model always remains consistent.

Entity objects map to database tables

When you use a Business Components for Java wizard to create entity objects from existing tables (reverse generation), it creates one entity object for each database table. It creates an entity object attribute for each column in the database table; each attribute can have the same name as the column or a different name that is more meaningful to your business application. The attribute definitions of an entity object reflect and enforce the properties of the respective database columns, including data types, column constraints, and precision and scale specifications.

An entity object can have an attribute for each column or you can use a subset, for example, if you don't need to work with that column or if a table contains information for more than one entity.

You can also use Business Components for Java wizards to define entity objects, and their attributes, without starting from an existing database table (forward generation). When you use a wizard to generate database tables from entity objects, it creates a table for each entity object, a table column for each entity attribute, and column constraints based on the entity attribute settings. In addition, you can use the Entity Constraint Wizard to define table constraints.

Multiple entity objects can map to the same table

Usually, one entity object maps to one database table. However, a table could store multiple categories of information, so you might need to map multiple entity objects to it.

You can apply different entity objects to different rows. For example, an Items table might store inventory items, requisition items, order items, and so on, in different rows of the table. For each type of row, you would define one type of entity object. In this case, you could have an Item entity object, and InventoryItem, RequisitionItem, and OrderItem entity objects that extend it. In addition, for each entity object, you would define one or more attributes to be a discriminator so the framework can automatically determine which rows map to which entity objects, and manage entity object storage. You would omit columns that do not apply to the entity object you are defining; however, each entity object must always include the primary key.

You should never map multiple entity objects to the same row.

Tools help you create entity objects

You can create and edit entity objects by using the Entity Object Wizard and Editor. For reverse generation, you can also use the Business Components Project Wizard or Package Wizard or Editor to create default entity objects. Default entity objects contain attributes for each column in the table; you can customize default entity objects in the Entity Object Editor.

Each entity object instance represents a row

During runtime, each entity object instance represents a row in the database table and stores its data. There is only one instance per row, and all instances of the same entity object class within the same transaction are cached together. Multiple view object queries returning the same row refer to the same entity object instance, so updates are visible to all view objects; one entity object can be used by multiple view objects. Each entity object instance is uniquely identified by its primary key attribute or attributes. For more detail, see How Does the Business Logic Tier Cache Data?

View rows can make entity object methods available to clients

For security reasons, entity objects are not exposed to clients. Instead, clients access an entity object’s data through one or more view objects. In the view row class, you can make entity object methods available to a client by writing a view row method that calls the method you want to expose. For example, you could use this feature to implement security: you could create different view objects so different clients have varying levels of access to entity object methods.

Associations represent relationships between entity objects

Relationships between entity objects are expressed through associations. They match attributes, typically key fields, from source and destination entity objects. Accessor methods that return rows and row sets through the association are available on the entity object class.

 

 

 


Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.