Modeling ObjEntities

Java object layer in Cayenne is modeled as a set of ObjEntities with relationships between them. Each consists of a reference to a (table). It also specifies the Java class for a business object and a set of attributes of this class.

A default set of ObjEntities is created during reverse engineering the database. It can be modified manually. E.g. certain entities may be excluded, certain attributes deleted if they are not a part of object layer. Some relationships can be "flattened" as described later in this chapter.

Modeler has a useful function that allows to update an ObjEntity after the changes were made to an underlying DbEntity. E.g. if a new database table called PAINTING_INFO was added, and a DbEntity created for this table, the following steps can be taken to quickly create a corresponding ObjEntity.

  • Create a new ObjEntity. Rename it to "PaintingInfo", specify the Java class.
  • From the dropdown of DbEntities select "PAINTING_INFO".
  • While the new entity is selected, from the "Project" menu select "Sync ObjEntity with DbEntity" item.
  • Inspect PaintingInfo attributes and relationships. A set of values matching the underlying DbEntity should've been created.

ObjEntity Qualifier

ObjEntities can hold a qualifier expression that is automatically appended to all SelectQueries rooted in a given ObjEntity. Entity qualifier can be viewed as a global data filter for a given entity. One area where this feature is used is inheritance mapping, however by itself it has nothing to do with inheritance as such and can be used standalone. To set an entity qualifier, type a Cayenne expression into the "Qualifier" field of the ObjEntity editor panel.