[Draft] Training Guide ‐ Hibernate - vinhtbkit/bkit-kb GitHub Wiki
Hibernate is an Object/Relational Mapping solution for Java environments. The term Object/Relational Mapping refers to the technique of mapping data from an object model representation to a relational data model representation (and vice versa).
Target: Knowledge about the Hibernate and how to use it effectively.
Expected Duration: 80 hours.
Qualification criteria:
- What is Hibernate?
- Mapping type in Hibernate?
- List the associations.
- Distinguish Hibernate and JPA.
Architecture [REQUIRED]
- Have an overview of the structure of Hibernate in in Spring.
Domain model [REQUIRED]
- Mapping types
- Basic values
- Embeddable values
- Entity types
- Naming strategies
- Identifiers
- Associations
- ...
Bootstrap [REQUIRED]
- How to config to bootstrap Hibernate:
- Native bootstrapping
- JPA bootstrapping
Schema Generation [REQUIRED]
- Know how to Hibernate generate the database from the entity mappings.
Persistence Context [REQUIRED]
- What is Persistence Context?
- The role of the Persistence Context.
Flushing [REQUIRED]
- Why do we need flushing?
Database Access [REQUIRED]
- How to connect Hibernate with the specific database?
Transactions [REQUIRED]
- What is a transaction?
- What is JTA?
- How to use?
- Transaction patterns?
Locking [REQUIRED]
- Optimistic Locking
- Pessimistic Locking
- How to apply with Hibernate?
Fetching [REQUIRED]
- When should the data be fetched? Now? Later?
- How should the data be fetched?
- Fetching types: static, dynamic
Batching [REQUIRED]
- How to deal with OutOfMenmory when using batching?
Caching [OPTIONAL]
- What is first level caching?
- What is second level caching?
- How to apply second level caching?
- Query caching, entity caching
Interceptors and Events [OPTIONAL]
- Hibernate provide the interface to help us intercept action of the Session
- Jakarta Persistence Callbacks
Java API for HQL and JPQL [REQUIRED]
- Distinguish HQL and JPQL
- How to use them?
Criteria [REQUIRED]
- Besides the HQL and JPQL we have the Criteria to help the query become more type-safe
- How to use the criteria?
Spatial [OPTIONAL]
- Hibernate provides the Spatial help we can handle the geographic data.
Hibernate Vector module [OPTIONAL]
- A vector database is a necessary database if we work with AI/ML.
References:
- https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html
- https://www.baeldung.com/hibernate-field-naming-spring-boot
- https://vladmihalcea.com/jpa-persist-merge-hibernate-save-update-saveorupdate
- https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#data.sql.datasource.connection-pool
- https://vladmihalcea.com/spring-transaction-connection-management/
- https://vladmihalcea.com/a-beginners-guide-to-transaction-isolation-levels-in-enterprise-java/
- https://vladmihalcea.com/optimistic-vs-pessimistic-locking/
- https://viblo.asia/p/phan-biet-giua-pessimistic-va-optimistic-locking-GrLZDVAg5k0
- https://thorben-janssen.com/hibernate-proxies/#:~:text=Hibernate%20generates%20proxies%20to%20provide,debugger%20or%20some%20log%20messages
Quizzes
-
Can you distinguish Hibernate and JPA?
-
What are the differences between hibernate
Session
and JPAEntityManager
? -
What's happened with this code:
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save( new Event( "Hello, this is an event!", new Date() ) );
session.flush();
session.getTransaction().rollback();
session.close();
- Finish all exercises of: https://docs.jboss.org/hibernate/orm/6.4/quickstart/html_single/