Tuesday 2 July 2019

Introduction to JPA


JPA stands for Java Persistence API, it specifies how to map a java object to RDBMS table record.

Let me explain with an example.

Let us take an Employee class.
package com.smaple.entities;

public class Employee {

 private int id;
 private String firstName;
 private String lastName;

 public int getId() {
  return id;
 }

 public void setId(int id) {
  this.id = id;
 }

 public String getFirstName() {
  return firstName;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public String getLastName() {
  return lastName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

}


JPA maps the entity class Employee to a RDBMS table.


Employee emp = new Employee();
emp.setId(1);
emp.setFirstName("Krishna");
emp.setLastName("Gurram");

By using JPA, we can map the Employee ‘emp’ definition is mapped to the record one of Employee table.

What are the ORM (Object Relational Mapping) frameworks that implement JPA?
There are many open source frameworks like EclipseLink, Hibernate etc., implements JPA specification.

Why do I go for ORM framework?
I already explained in my previous post, I would recommend you to go through my below tutorial

Previous                                                    Next                                                    Home

No comments:

Post a Comment