blob: 35ca95b4501ea9c1ebbb83d057ff3b68d9a6b64a [file] [log] [blame]
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 <A href="http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/map/ObjEntity.html" class="external-link" rel="nofollow">ObjEntity</A> consists of a reference to a <A href="http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/map/DbEntity.html" class="external-link" rel="nofollow">DbEntity</A> (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 &quot;flattened&quot; 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 &quot;PaintingInfo&quot;, specify the Java class.</LI>
<LI>From the dropdown of DbEntities select &quot;PAINTING_INFO&quot;.</LI>
<LI>While the new entity is selected, from the &quot;Project&quot; menu select &quot;Sync ObjEntity with DbEntity&quot; 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 &quot;Qualifier&quot; field of the ObjEntity editor panel. Valid expressions grammar is described <A href="http://www.objectstyle.org/cayenne/grammar/ExpressionParser.html" class="external-link" rel="nofollow">here</A>.</P>