Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Introduction to JPA Framework

361 vues

Publié le

Java Persistence API is a collection of classes and methods to persistently store the vast amounts of data into a database which is provided by the Oracle Corporation.
Generally, Java developers use lots of code, or use the proprietary framework to interact with the database, whereas using JPA, the burden of interacting with the database reduces significantly. It forms a bridge between object models (Java program) and relational models (database program).

Publié dans : Technologie
  • Identifiez-vous pour voir les commentaires

  • Soyez le premier à aimer ceci

Introduction to JPA Framework

  1. 1. Introduction to JPA Framework www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
  2. 2. Content Content Introduction JPA API Overview Database Table and Schema JPA Installation and Setup Configuration – Persistent Unit Persistence Object or Entity Bean Entity Annotations Mapping an Object - O-R Mappings Joins and Collections Creating Entity Manager Using Entity Manager Persistent Types Using Entity Transactions Querying – JPQL Testing the Entity Bean Writing Test Cases CRUD Operations on Entity Beans About Us www.collaborationtech.co.in
  3. 3. Content Inheritance Mapping Single Table Inheritance Join Table Inheritance Entity Bean Lifecycle Data relationships One-to-one relationships Bidirectional one-to-one relationships Many-to-one relationships bidirectional many-to-one relationship One-to-many relationships Bidirectional One-to-many relationships Many-to-many relationships Bidirectional many-to-many relationships Writing Service Using JPA Using JPA with Spring www.collaborationtech.co.in
  4. 4. Introduction  Java Persistence API is a collection of classes and methods to persistently store the vast amounts of data into a database which is provided by the Oracle Corporation.  Generally, Java developers use lots of code, or use the proprietary framework to interact with the database, whereas using JPA, the burden of interacting with the database reduces significantly. It forms a bridge between object models (Java program) and relational models (database program).  Java Persistence API (JPA) is the Java standard for mapping Java objects to a relational database.  The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. www.collaborationtech.co.in
  5. 5. Database Table and Schema The name of the schema to be used in MySQL is "mydb", but if you decide to use a different one just remember to change any reference to mydb to the name of your Schema. First let us start by creating the following table in MySQL: CREATE TABLE IF NOT EXISTS `mydb`.`company` ( `idcompany` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(45) NOT NULL , `country` VARCHAR(45) NOT NULL , `privat` TINYINT(1) NOT NULL DEFAULT 0 , `ownername` VARCHAR(45) NULL , `numberemployees` INT NOT NULL DEFAULT 0 , `income` DOUBLE NOT NULL DEFAULT 0.0 , PRIMARY KEY (`idcompany`) www.collaborationtech.co.in
  6. 6. JPA Installation & Setup JPA can be easily installed and integrated with your current Java environment following a few simple steps without any complex setup procedures. Step 1: Installing JPA Download Eclipse IDE form following link https://www.eclipse.org/downloads/ Installing JPA using Eclipselink Eclipselink is a library therefore we cannot add it directly to Eclipse IDE. For installing JPA using Eclipselink you need to follow the following steps. Create a new JPA project by selecting File->New->JPA Project in the Eclipse IDE. www.collaborationtech.co.in
  7. 7. JPA Installation & Setup  You will get a dialog box named New JPA Project. Enter project name ‘Collaba’, check the jre version and click next.  Click on download library (if you do not have the library) in the user library section.  Select the latest version of Eclipselink library in the Download library dialog box and click next.  Accept the terms of license and click finish for download library.  You will find the process of downloading a file.  After downloading, select the downloaded library in the user library section and click finish.  Finally you get the project file in the Package Explorer in Eclipse IDE. Extract all files, you will get the folder and file hierarchy. www.collaborationtech.co.in
  8. 8. JPA Installation & Setup Adding MySQL connector to Project MySQL database for database operations. It requires mysql-connector jar to interact with java program. Follow the steps to configure database jar to your project.  Go to Project properties -> Java Build Path by right click on it. You will get a dialog box as follows: Click on Add External Jars.  Go to the jar location in your system memory, select and click on open.  Click ok on properties dialog. You will get the MySQL-connector Jar into your project. Now you are able to do database operations using MySQL. www.collaborationtech.co.in
  9. 9. Persistence  JPA Persistence Unit is a logical grouping of user defined persistable classes (entity classes, embeddable classes and mapped superclasses) with related settings.  Persistence units are defined in a persistence.xml file, which has to be located in the META-INF directory in the classpath persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="Eclipselink_JPA" transaction-type="RESOURCE_LOCAL"> <class>com.collaba.eclipselink.entity.BookEntityBean</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpatest"/> <property name="javax.persistence.jdbc.user" value="jpa"/> <property name="javax.persistence.jdbc.password" value="root"/> <property name ="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="eclipselink.logging.level" value="FINE"/> <property name="eclipselink.ddl-generation" value="create-tables"/> </properties></persistence-unit></persistence> www.collaborationtech.co.in
  10. 10. Follow us on Social Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU
  11. 11. About Us

×