Tutorial Object Relational MappingPage added by Andrus AdamchikThe goal of this section is to learn how to create a simple Object-Relational model with CayenneModeler. We will create a complete ORM model for the following database schema: Unable to render embedded object: File (database-schema.jpg) not found.
Mapping Database Tables and ColumnsLets go back to CayenneModeler where we have the newly created project open and start by adding the ARTIST table. Database tables are called "DbEntities" in Cayenne mapping (those can be actual tables or database views). Select "UntitledDomainMap" on the left-hand side project tree and click "Create DbEntity" button (or use "Project > Create DbEntity" menu). A new DbEntity is created. In "DbEntity Name" field enter "ARTIST". Then click on "Create Attribute" button on the entity toolbar (third button from the left). This action changes the view to the "Attribute" tab and adds a new attribute (attribute means a "table column" in this case) called "untitledAttr". Let's rename it to ID, make it an INTEGER and make it a PK: Unable to render embedded object: File (modeler-artistid.png) not found. Similarly add NAME VARCHAR(200) and DATE_OF_BIRTH DATE attributes. After that repeat this procedure for PAINTING and GALLERY entities to match DB schema shown above.
Mapping Database RelationshipsNow we need to specify relationships between ARTIST, PAINTING and GALLERY tables. Start by creating a one-to-many ARTIST/PAINTING relationship:
Unable to render embedded object: File (modeler-dbrelationship.png) not found.
Mapping Java ClassesNow that the database schema mapping is complete, CayenneModeler can create mappings of Java classes (aka "ObjEntities") by deriving everything from DbEntities. At present there is no way to do it for the entire DataMap in one click, so we'll do it for each table individually.
Now you need to synchronize relationships. Artist and Gallery entities were created when there was no related "Painting" entity, so their relationships were not set.
Unless you want to customize the Java class and property names (which you can do easily) the mapping is complete. Next Step: Tutorial Java Classes
Change Notification Preferences
View Online
|
Add Comment
|
- [CONF] Apache Cayenne Documentation > Tutorial Object Relati... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
- [CONF] Apache Cayenne Documentation > Tutorial Object R... confluence
