| Title: Modeling ObjEntities |
| |
| |
| <H3><A name="ModelingObjEntities-ModelingObjEntities"></A>Modeling ObjEntities</H3> |
| |
| <P>Java object layer in Cayenne is modeled as a set of ObjEntities with relationships between them. Each <TT>org.apache.cayenne.map.ObjEntity</TT> consists of a reference to a <TT>org.apache.cayenne.map.DbEntity</TT> (table). It also specifies the Java class for a business object and a set of attributes of this class.</P> |
| |
| <P>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.</P> |
| |
| <P>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.</P> |
| <UL> |
| <LI>Create a new ObjEntity. Rename it to "PaintingInfo", specify the Java class.</LI> |
| <LI>From the dropdown of DbEntities select "PAINTING_INFO".</LI> |
| <LI>While the new entity is selected, from the "Project" menu select "Sync ObjEntity with DbEntity" item.</LI> |
| <LI>Inspect PaintingInfo attributes and relationships. A set of values matching the underlying DbEntity should've been created.</LI> |
| </UL> |
| |
| |
| <H4><A name="ModelingObjEntities-ObjEntityQualifier"></A>ObjEntity Qualifier</H4> |
| |
| <P>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 <A href="modeling-inheritance.html" title="Modeling Inheritance">inheritance mapping</A>, 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.</P> |