This repository contains multiple projects that demonstrate different aspects of Hibernate, a popular Object-Relational Mapping (ORM) framework for Java. The projects showcase how Hibernate can be used to interact with relational databases in a Java application, focusing on CRUD operations, entity relationships, and more. The purpose of these projects is to deepen understanding of Hibernate and ORM concepts.
- Entity Mapping: Demonstrates the mapping of Java objects to database tables.
- CRUD Operations: Implementation of Create, Read, Update, and Delete functionalities using Hibernate.
- Entity Relationships: Covers One-to-One, One-to-Many, and Many-to-Many relationships.
- Database Configuration: Integrates with relational databases such as MySQL.
- Learning-Focused: Projects were developed as part of a learning journey to grasp Hibernate concepts.
- One-to-One
- One-to-Many
- Many-to-One
- Many-to-Many
- Java 17
- Hibernate 5.x
- MySQL
- Maven
- JPA Annotations
-
Entity Classes:
- Represents the database tables and are mapped using JPA annotations.
@Entity @Table(name = "entity_table") public class EntityClass { // Fields, Getters, Setters, and Mappings }
-
Hibernate Configuration:
- The
hibernate.cfg.xml
file is used to configure the database connection and Hibernate properties.
<hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate_db</property> <!-- Other properties --> </session-factory> </hibernate-configuration>
- The
-
DAO Classes:
- Data Access Object classes that handle CRUD operations using Hibernate SessionFactory.
public class EntityDAO { // Methods for CRUD operations }
This repository follows a structured commit strategy to document the learning journey:
- Initial Setup Commits: Focus on project scaffolding, setting up Hibernate configuration files, and integrating database connections.
- Feature Addition Commits: Each commit aligns with the addition of a specific feature (e.g., One-to-Many relationship mapping) to demonstrate incremental learning.
- Bug Fix and Refactor Commits: Commit messages detail the resolution of issues encountered while learning concepts such as lazy loading, eager fetching, and session management.
- Documentation and Comment Commits: Includes commits aimed at enhancing the codebase with comments and documentation to reinforce understanding.
These commit patterns not only track progress but also highlight the learning curve associated with mastering Hibernate’s core concepts.
- Clone the repository:
git clone https://github.com/MalingaBandara/hibernate-projects.git
- Set up the MySQL database and update the
hibernate.cfg.xml
with your configurations. - Run the application using Maven:
mvn clean install
These projects were developed as part of a learning journey to understand Hibernate and ORM concepts. Future enhancements could include exploring advanced Hibernate features such as caching, fetching strategies, and criteria queries.
This project is licensed under the MIT License.