This repository contains the source code and configuration files for the Hibernate Assignment on ORM Concepts. The assignment is divided into two parts: Part 1 covers CRUD operations on a single entity (Book
), and Part 2 focuses on relationships between entities (Book
and Author
) using Hibernate.
The objective of Part 1 is to assess the student's ability to use Hibernate for performing CRUD operations on a single entity (Book
). Students will focus on the Book
entity and its associated attributes.
- Set up a Java project and configure Hibernate with a suitable database (e.g., MySQL, H2) for this assignment.
- Create the necessary Java classes representing the
Book
entity with appropriate annotations for mapping. - Implement the following CRUD operations for the
Book
entity:- Create a new book and save it to the database.
- Retrieve a book by its ID from the database.
- Update an existing book's attributes (e.g., title, ISBN) and save the changes to the database.
- Delete a book from the database.
- Test the CRUD operations to ensure they are working correctly by using a simple console-based application.
The objective of Part 2 is to assess the students' understanding of creating and managing various types of relationships between entities using Hibernate. The students will work with two entities: Book
and Author
.
- Create the necessary Java classes representing the
Book
andAuthor
entities with appropriate annotations for mapping. - Implement the following relationships between entities using Hibernate annotations:
- One-to-One: Each book can have only one author. Update the
Book
entity to have a one-to-one relationship with theAuthor
entity. - One-to-Many: Each author can have multiple books. Update the
Author
entity to have a one-to-many relationship with theBook
entity. - Many-to-Many: Each book can have multiple authors, and each author can have multiple books. Implement a many-to-many relationship between the
Book
andAuthor
entities.
- One-to-One: Each book can have only one author. Update the
- Implement the following tasks related to relationships:
- Save the
Author
entity independently, and then associate it with the correspondingBook
using the one-to-one relationship. - Save the
Book
entities independently, and then associate each book with its respectiveAuthor
using the one-to-many relationship. - Implement the many-to-many relationship by introducing a join table (association table) to manage the relationship between
Book
andAuthor
entities. SaveBook
andAuthor
entities independently, and then associate them using the many-to-many relationship.
- Save the
- Test the relationships by creating authors and books, ensuring that the relationships are correctly maintained.
README.md
file providing a brief description of the assignment, instructions on how to run the application, and any important notes.- Clone or download this GitHub repository to your local machine.
- Set up a suitable database (e.g., MySQL, H2) and configure the database connection details in the project's configuration files.
- Build and run the Java project.
- The console-based application will guide you through testing the CRUD operations and entity relationships.
- Ensure you have Java Development Kit (JDK) installed on your machine.
- Make sure the required dependencies (e.g., Hibernate) are added to the project.
- Double-check the database configuration to ensure proper connectivity.
- Follow the best practices for code organization and documentation.