Easy way to learn Spring Data JPA,Hibernate Introduction
What is JPA?
The java persistence API is used to persist data between java object and relational database. JPA acts like a middle ware between object oriented domain models and relational database.
Its just a specification of Java EE, its does not perform any operation by itself because its does not provides any implementation classes. The API jar just contains the set of interface which can use to implement the methods and persist data into the service layer. But we can't use JPA on its own. We need a JPA provider which implements the specification like ORM(Object Relational Mapping) tools like Hibernate,TopLink etc.
Object Relational Mapping(ORM):
Object Relational Mapping (ORM) is a functionality which is used to develop and maintain a relationship between an object and relational database by mapping an object state to database column. It is capable to handle various database operations easily such as inserting, updating, deleting etc.
What is Hibernate Framework?
Hibernate is an object-relational mapping solution for java environments which comes with an abstraction layer and handles the implementation internally. In another way,we can say that, Hibernate is java-based ORM tool that provides a framework for mapping application domain object to the relational databases table.
One of the major advantage is Hibernate provides a reference implementation of the java Persistence API that makes it a great choice as ORM tool with benefits of loose coupling.
**JPA is a specification and Hibernate is a JPA provider or implementation.**
JPA Entity Class:
To able to store all objects in the database using JPA we need to define an entity class. Basically, entities in JPA are nothing but POJOs representing data that can be persisted to the database. An entity represents a table stored in a database. Every instance of an entity represents a row in the table.
- Using @Entity annotation we can make a class as entity class.
- @Table annotation used for specifies the table name where all data of this entity is to be persisted but if we don't use this annotation, hibernate will use the class name as the table name by default.
- @Id is used for makes the identifiers for the entity that is the primary key of a table.
- @GeneratedValue is used for auto increment the value.
- @Column annotation specifies the details of the column for this property or field. If @Column annotation is not specified, property name will be used as the column name by default.
--This is the small introduction. --
Comments
Post a Comment