A hands-on repository for learning and practicing Hibernate ORM with Java.
This project contains practical examples and exercises covering the core concepts of Hibernate, from basic configuration and CRUD operations to entity relationships, HQL, JPQL, transactions, and database integration.
Hibernate is a popular Object-Relational Mapping (ORM) framework for Java applications. It simplifies database interaction by allowing Java objects to be mapped to database tables.
The purpose of this repository is to understand Hibernate concepts through practical examples rather than only theoretical learning.
- Understand the fundamentals of Hibernate ORM
- Configure Hibernate with a Java application
- Connect Java applications with relational databases
- Perform CRUD operations using Hibernate
- Understand entity mapping
- Work with primary keys and generated IDs
- Understand Hibernate sessions and session factories
- Learn Hibernate Query Language (HQL)
- Learn Java Persistence Query Language (JPQL)
- Implement entity relationships
- Understand transactions
- Explore lazy and eager loading
- Understand the Hibernate persistence lifecycle
- Java
- Hibernate ORM
- JPA / Jakarta Persistence
- JDBC
- MySQL
- Maven
- IntelliJ IDEA / Eclipse
- Hibernate introduction
- ORM concepts
- Hibernate architecture
- Hibernate configuration
- SessionFactory
- Session
- Transaction
@Entity@Table@Id@GeneratedValue@Column- Primary key mapping
- Database table mapping
- Create
- Read
- Update
- Delete
- Persisting Java objects
- Retrieving entities
- One-to-One
- One-to-Many
- Many-to-One
- Many-to-Many
- Foreign key mapping
- Join tables
- HQL
- JPQL
- Query parameters
- Filtering
- Sorting
- Joins
- Transaction management
- Commit
- Rollback
- Transaction boundaries
- Lazy loading
- Eager loading
- Fetch strategies
- N+1 query problem
hibernate-learning/
│
├── src/
│ ├── main/
│ │ └── java/
│ │ └── ...
│ │
│ └── resources/
│ └── ...
│
├── pom.xml
└── README.md
The structure may evolve as new Hibernate concepts and examples are added.
Make sure you have the following installed:
- Java JDK
- Maven
- MySQL
- An IDE such as IntelliJ IDEA or Eclipse
git clone https://github.com/YOUR_USERNAME/hibernate-learning.gitcd hibernate-learningCreate a MySQL database and update the Hibernate/database configuration with your credentials.
Example:
hibernate.connection.url=jdbc:mysql://localhost:3306/hibernate_db
hibernate.connection.username=root
hibernate.connection.password=your_passwordmvn clean installRun the relevant Java classes from your IDE or using Maven.
The repository focuses on understanding how this:
Java Object
↓
Hibernate ORM
↓
SQL
↓
Relational Database
works in practice.
For example:
Student student = new Student();
student.setName("John");
student.setAge(22);
session.persist(student);Hibernate handles the conversion between the Java object and the corresponding database record.
- Hibernate fundamentals
- Hibernate configuration
- Entity mapping
- CRUD operations
- Entity relationships
- HQL
- JPQL
- Transactions
- Lazy & eager loading
- Hibernate caching
- Advanced mappings
- Performance optimization
This repository may be expanded with:
- Spring Data JPA
- Spring Boot + Hibernate
- Advanced JPA mappings
- Criteria API
- Hibernate caching
- Query optimization
- Database performance
- Hibernate with REST APIs
This repository is created as part of my journey to strengthen my Java backend development and ORM fundamentals through practical implementation.
Each example is intended to build a stronger understanding of how Java applications communicate with relational databases using Hibernate.
⭐ If you find this repository useful, feel free to explore the examples and learn along with me.