| --- |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| title: Modeling ObjEntities |
| url: /docs/1.2/modeling-objentities.html |
| layout: docs_legacy |
| --- |
| |
| |
| |
| <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 "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. Valid expressions grammar is described <A href="http://www.objectstyle.org/cayenne/grammar/ExpressionParser.html" class="external-link" rel="nofollow">here</A>.</P> |