- About The Project
- Why The Project Is Created?
- Used Technologies
- Images
- Requirements
- Quick Start
- Installation (Run In IntelliJ IDEA)
- Custom Terminal Features
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.
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.
- 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.
Windows CMD Output
This may looks hard to understand but it is easy. Get relax.
- Main process is about saving a new Student.
- Instead of typing Student's grade, a new terminal commands is typed as
>> -r -A
which meansread Address
. - After completed 2. process, come back to 1. process. But again, terminal commans is typed. This time
>> -c -A
which meanscreate Addres
- After compoeted 3. process, come back to 1. process again. And this time just goes on 1. process.
IntelliJ IDEA Output
- JDK 11
- IntelliJ IDEA (Community Edition)
- MySQL
- Username:
root
- Password:
- port::
3306
- Username:
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
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 bothpersistenceUnitRealProject
andpersistenceUnitTest
)
- src/main/resources/META-INF/
<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
- src/main/resources/hibernate.cfg.xml/
<property name="connection.url">jdbc:mysql://localhost:YOUR_PORT/school_db?allowPublicKeyRetrieval=true&useSSL=false&createDatabaseIfNotExist=true</property>
<property name="connection.username">YOUR_USERNAME</property>
<property name="connection.password">YOUR_PASSWORD</property>
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
).
- Lower cases present CRUD operation (
Example Using | Meaning |
---|---|
-q | Cancel Current Process |
-e | Exit Program |
-h | Help |
Shortcut Command | Long Command | Shortcut Object | Normal Object |
---|---|---|---|
-c | create | -A | Address |
-r | read | -S | Student |
-u | update | -C | Course |
-d | delete | -ER | ExamResult |
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 |
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 |