Overview Topics
- Revise Hibernate (with code walk through)
- SessionFactory API
openSession
vs getCurrentSession
- Entity state transitions
- Transient, persistent, detached, removed
- CRUD operations
- JPQL (Java Persistence Query Language)
Learning Objectives
0. Save User Details (already done)
- Input: User details
- Output: A status message
1. Get User Details by ID
- Input: User ID
- Output: Null or actual user details
Session API for Entity Retrieval by ID
public <T> T get(Class<T> class, Object id) throws HibernateException
- T: Type of the entity (POJO)
- Returns:
null
in case of invalid ID
- OR PERSISTENT entity reference
- Note: In earlier versions (till Hibernate 5.x), ID property was required to be Serializable
2. Get All Users
- Output: Display all user details