Skip to content

AhmetEminSaglik/JPA-vs-Hibernate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hibernate-vs-Jpa-Implementation

"images/jpa-hibernate.gif"

Content

  1. About The Project
  2. Why The Project Is Created?
  3. Used Technologies
  4. Images
    1. Windows CMD Output
    2. Intellij IDEA Output
  5. Requirements
  6. Quick Start
    1. Run in CMD
  7. Installation (Run In IntelliJ IDEA)
  8. Custom Terminal Features

1-) About The Project

Hibernate-vs-JPA-Implementation is a console application designed to demonstrate the use of both JPA and Hibernate in core Java. This project includes classes for managing addresses, students, courses, and exam results. Users can easily select either JPA or Hibernate to perform database operations, and the application features color-coded outputs for a more user-friendly console experience.

Most important part of this project is providing user the shortcut terminal commands to process. Detail information can be found in Custom Terminal Features.

2-) Why The Project Is Created?

During interviews, I was asked a few times about my experience with JPA and Hibernate tools. While I mentioned that I use JPA within Spring Boot, some interviewers preferred not to consider that experience, as JPA is integrated into Spring Boot. To address this, I decided to create a project that allows for easy switching between JPA and Hibernate, enabling a clear demonstration of both frameworks in action. This project serves as a practical example of JPA and Hibernate implementations.

3-) Used Technologies

  • Core Technologies:
    • JAVA SE
    • Log4j
    • MySQL
  • Dependencies:
    • org.hibernate.hibernate-core:6.2.8.Final
    • log4j.log4j:1.2.17
    • mysql.mysql-connector-java:8.0.31
    • org.junit.jupiter.junit-jupiter:RELEASE
    • javazoom.jlayer:1.0.1
      • To play music background while running the program.
    • jitpack.io repository
      • To get the latest version of the console-colorful-text library.
    • com.github.AhmetEminSaglik:Console-Colorful-Text:v1.1
      • To print colorful both Cmd and Intellij Idea.

4-) Images

Windows CMD Output

1. Activating CMD Printing Tool.

"images/cmd/1.png"

2. Activating ORM Logs

"images/cmd/2.png"

3. Activating JPA

"images/cmd/3.png"

4. Saving Address Data (ORM Logs from for JPA Implementation)

"images/cmd/5.png"

5. Find All Address Data (ORM Logs from for Hibernate Implementation)

"images/cmd/7.png"

1. Custom Terminal Commands - Help .

"images/cmd/21.png"

2. Custom Terminal Commands - Inner process .

This may looks hard to understand but it is easy. Get relax.

  1. Main process is about saving a new Student.
  2. Instead of typing Student's grade, a new terminal commands is typed as >> -r -A which means read Address.
  3. After completed 2. process, come back to 1. process. But again, terminal commans is typed. This time >> -c -A which means create Addres
  4. After compoeted 3. process, come back to 1. process again. And this time just goes on 1. process.

"images/cmd/21.png"

8. Find All Student Data

"images/cmd/11.png"

10. Saving New Course - Other Course

"images/cmd/13.png"

12. Student Save process invalid input and try to save without address data.

"images/cmd/15.png"

17. Save Exam Result - Course step and score.

"images/cmd/20.png"


IntelliJ IDEA Output

1. Activating IDEA Printing Tool.

"images/idea/1.png"

2. Retrieve all Exam Result data.

"images/idea/3.png"

3. Retrieve all Exam Result data by invalid Course Name.

"images/idea/4.png"

4. Retrieve all Exam Result data by Course Name.

"images/idea/6.png"

5-) Requirements

6-) Quick Start

Run In Windows CMD

1. First of all, the project requires a running MySQL server. If you have not yet installed a MySQL server but docker desktop, then you can copy and paste the following command to your CMD to create a proper MySQL container to run the project.
Default login credentials must be the same as given in requirements part.
(If you want to change login credentials please go to installation part.)

docker run --name jpa-hibernate-mysql -p 3306:3306  -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -d mysql

To test whether the MySQL container is running properly, you can copy and paste the following command.

docker ps

If you see running a docker container named jpa-hibernate-mysql then it means you successfully launched the MySQL.

2. Copy and paste the following command in your cmd.

git clone https://github.com/AhmetEminSaglik/JPA-vs-Hibernate.git

3. Copy and paste the following command into your cmd.

java -jar  JPA-vs-Hibernate/Jpa-vs-Hibernate.jar

7-) Installation (Run In IntelliJ IDEA)

1. Copy and paste the following command in your cmd.

git clone https://github.com/AhmetEminSaglik/JPA-vs-Hibernate.git

2. To run this project one dependency must be added to the project. You can go to following link to figure out how to install it directly to the project.

3. If you want to change mysql connect data then update both JPA and Hibernate configuration files.

  • JPA configuration file :
    • src/main/resources/META-INF/persistence.xml
      (update both persistenceUnitRealProject and persistenceUnitTest)
<property name="jakarta.persistence.jdbc.url"
          value="jdbc:mysql://localhost:YOUR_PORT/school_db_test?createDatabaseIfNotExist=true"/>
<property name="jakarta.persistence.jdbc.user" value="YOUR_USERNAME"/>
<property name="jakarta.persistence.jdbc.password" value="YOUR_PASSWORD"/>
  • Hibernate configuration file :
    • src/main/resources/hibernate.cfg.xml/hibernate.cfg.xml
    • src/main/resources/hibernate.cfg.xml/hibernate_test.cfg.xml
<property name="connection.url">jdbc:mysql://localhost:YOUR_PORT/school_db?allowPublicKeyRetrieval=true&amp;useSSL=false&amp;createDatabaseIfNotExist=true</property>
<property name="connection.username">YOUR_USERNAME</property>
<property name="connection.password">YOUR_PASSWORD</property>

8-) Custom Terminal Features

This feature is added to make this project extraordinary, making not an ordinary project.
NOTE: >> is default prefix to run in Custom Terminal. It can be switch in program. After launch the program, Main > setting > Update Terminal Prefix.
NOTE: To use Custom terminal feature, prefix must be added.
Example : >> -h, >> -r -S, >> -q,>> -e

  • Core commands must be use alone (>>-q).
  • Standard Commands must be use together (>>-r -S).
    • Lower cases present CRUD operation (-r).
    • Upper cases present Object (-S).

1. Terminal - Core Commands

Example Using Meaning
-q Cancel Current Process
-e Exit Program
-h Help

2. Terminal - Standart Commands (Process Data Commands)

Shortcut Command Long Command Shortcut Object Normal Object
-c create -A Address
-r read -S Student
-u update -C Course
-d delete -ER ExamResult

3.Terminal Commands - One Command ~ Multi Syntax

Example Using (Shortcut-Commands) Example Using (Standard-Commands) Meaning
-c -A create Address Creates Address
-A -c create Address Creates Address
-c Address create Address Creates Address
-A create create Address Creates Address
create -A create Address Creates Address
Address -c create Address Creates Address
create Address create Address Creates Address
Address create create Address Creates Address

3.Terminal Commands - Example Usage

Example Using (Shortcut-Commands) Example Using (long-Commands) Meaning
-h help Prints how to use Custom Terminal feature
-q quit Cancel current Process
-r -S read Student Read Student
-u -C update Course Updates Course
-d -ER delete ExamResult Deletes Exam Result

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published