SlideServe
Menu
Préférences
© SlideServe · v2026

Apache Cayenne Object Relational Mapping

yasuo avatar
15 diapositives · 447 Views · Jul 24, 2014

Apache Cayenne Object Relational Mapping. What is ORM?. ORM stands for Object Relational Mapping. It is a technique that creates an object oriented data model on top of a Relational Database. Persistence.

Apache Cayenne Object Relational Mapping - slide 1
01 / 15Apache Cayenne Object Relational Mapping
1 / 17

Télécharger la présentation

Apache Cayenne Object Relational Mapping
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Apache Cayenne Object Relational Mapping

  2. What is ORM? • ORM stands for Object Relational Mapping. • It is a technique that creates an object oriented data model on top of a Relational Database.

  3. Persistence • Persistence means that the data used in a software application survives the application process. • In other words, once you stop using or close the application the data will remain stored in a (relational) database. • In Java terms, we would like the state of some of our objects to live beyond the JVM so that the same state is available later.

  4. Object-Relational Impedance Mismatch • Impedance mismatch refers to the structural differences between a Relational Database and an Object Oriented Database. • In order to do the mapping between both, we must overcome the following problems: • Granularity. • Subtypes (Inheritance). • Identities. • Associations. • Access to the information.

  5. Frameworks for ORM • Hibernate. • EclipseLink. • Data Knowledge Objects. • jOOQ. • Enterprise Java Beans EJB3. • Apache Cayenne.

  6. Prerequisites • Have already installed: • Java 7. • Eclipse EE with Maven plugin. • Install any *AMP server or MySQL from scratch. • Apache Cayenne Modeler 3.0 version. • MySQL JDBC driver. • It is important to have the required versions because there are syntax changes from version to version.

  7. Getting Started • The next step is to follow the Getting Started tutorial from the Cayenne website: • https://cayenne.apache.org/docs/3.0/tutorial-starting-project.html • We are going to build a simple web application that has this database design:

  8. Hands On • Create a Maven Project in Eclipse. • File > New > Project > Other > Maven > Maven Project > Simple project • Group Id: org.example.cayenne • Artifact Id: tutorial • Create a Cayenne Modeler Project. • New Project > Project • DataDomainName > datadomain • Create a MySQL database in PHPMyAdmin • Startthe Apache and MySQL servers • Open PHPMyAdmin • Databases > testdb > Create

  9. Cayenne Modeler New Project > Project Create Data Node > datanode • Datanode Name: datanode • JDBC Driver: com.mysql.jdbc.Driver • DB URL: jdbc:mysql://localhost:3306/testdb (port might change) • User: root • Password: Create DataMap • DataMap Name: datamap • DataNode: datanode • Java Package: org.example.cayenne.persistent • Save the project in: tutorial/src/main/resources

  10. Cayenne Modeler Createthedatabasetables: • datamap> Create DB Entity • Name: ARTIST • CreateAttribute: ID, INTEGER, PK • RepeatthestepsforthePainting and Gallerytables. Create relations between tables: • Select DB Entity ARTIST. • Select Relationships and Create Relationship. • Target: Painting. • Select Database Mapping. Relationship: PAINTING; Reverse: ARTIST; Source: ID; Target: ARTIST_ID • In the paintings relation from ARTIST select To Many. • In the artist relation from PAINTING unselect To Many. • Repeat the same process for the GALLERY to PAINTING relation.

  11. Cayenne Modeler Create entities for class generation: • Right click on ARTIST and click CREATE OBJECT ENTITY. • Select the generated object and click synchronize relationships. Generate Java Classes: • Tools > Generate Classes • Output Directory: tutorial/src/main/java • Classes > Check All Classes • Generate

  12. Eclipse Refresh the workspace and solve the dependencies: • Refresh (F5). • Edit the file pom.xmlto look like in the following link: • http://cayenne.apache.org/docs/3.0/tutorial-java-classes.html

  13. Cayenne Modeler Generate the Database Schema: • Tools > Preferences > ClassPath > Add Jar and select the JAR file for MySQL Connector J • Tools > Generate Database Schema. • Username: root • Password:

  14. Eclipse Create Main class in the org.example.cayenne package. • http://cayenne.apache.org/docs/3.0/tutorial-objectcontext.html • Add the MySQL J Connector dependency to the pom.xmlfile. • http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.27 Refer to the following page in the tutorial: • http://cayenne.apache.org/docs/3.0/tutorial-persistent-objects.html • Add the setDateOfBirth method to Artist.java • In the Main class, write the code to add one painter, two paintings and one gallery. • Run the code and check the results in phpMyAdmin. • Then try the delete rules proposed in the tutorial: • http://cayenne.apache.org/docs/3.0/tutorial-delete.html

  15. Eclipse Go to http://cayenne.apache.org/docs/3.0/tutorial-webapp.html in order to convert our Applcation it into a Web Application: • Create the folder src/main/webapp/WEB-INF • Create the file web.xml into src/main/webapp/WEB-INF • Create the file webapp/index.jsp • Create the file webapp/detail.jsp • Add the dependencies of maven-jetty-plugin to the pom.xml Create an execution configuration for Maven: • Run > Run Configurations > Maven Build > New • Name: cayenne-tutorial • Base directory: ${workspace_loc:/tutorial} • Goals: jetty:run • Apply > Run • Go to http://localhost:8080/tutorial/ • Enhance your web application so it can add paintings to an artist.