JPA – Java persistance API – it is a tool that allows programmers to map Java objects onto database tables and operate on them with objective approach instead of SQL.
1.Entity Creation
@Entiy means its JPA entity
@Table – it is mapped on Author table in database
@Id – it is a key
@GeneratedValue – 1,2,3…
@ManyToOne(cascade) – means that CRUD operation will also effect bounded Author entity in database
@JoinColumn – joins with id
- Hibernate DDL -Hibernate is ORM(Object Relational Mappin) framework for Java. It is used to map Java object onto Database
-Take care of CRUD operations
-Thanks to Hibernate it is easier to change Database
- Creating Entities
- Add, FindOne
CRUD repository automatically creates CRUD operations
Save(), findById() – thats all
- Findall, update, delete
Findall:
Update:
Delete:
- CustomQueries
Thats all… you dont need to do anything, JPA is clever enough to look at authors and get with age less, based just on name of the method
7.HQL
HQL – Hibernate query language. HQL is similiar to SQL but works on Java objects instead of SQL tables
We make this name on purpose
Select all objects marked as a where age is …