Skip to content

Commit

Permalink
adding some images
Browse files Browse the repository at this point in the history
  • Loading branch information
giriharan13 committed Oct 5, 2023
1 parent 57062f5 commit fab9e49
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 9 deletions.
File renamed without changes
File renamed without changes
Binary file added setup/images/congrats.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added setup/images/db1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added setup/images/db2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
28 changes: 19 additions & 9 deletions setup/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,43 @@ Make sure you have these installed in your system

1. Open Eclipse IDE.
2. Go to `File -> New -> Maven Project.
(img)
![mav1](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/mav1.jpg?raw=true)
3. Follow the images below
(img)
![mav2](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/mav2.jpg?raw=true)
![mav3](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/mav3.jpg?raw=true)
![mav4](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/mav4.jpg?raw=true)
4. Click `Finish` to create the project.
![mavaft](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/mavaft.jpg?raw=true)

## Step 2: Add Dependencies

1. Open the `pom.xml` file in your Maven project.
2. Add the following dependencies for [Hibernate Core](https://mvnrepository.com/artifact/org.hibernate/hibernate-core/5.6.15.Final) and [MySQL Connector](https://mvnrepository.com/artifact/com.mysql/mysql-connector-j):(img)


2. Add the following dependencies for [Hibernate Core](https://mvnrepository.com/artifact/org.hibernate/hibernate-core/5.6.15.Final) and [MySQL Connector](https://mvnrepository.com/artifact/com.mysql/mysql-connector-j):![pomxml](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/pomxml.jpg?raw=true)
3. Save the `pom.xml` file.

## Step 3: Create a Database

1. Using MySQL, create a new database.
2. Inside the database, create a table that corresponds to the entity you want to map using Hibernate.

Here I'm creating a database called "db" and a table name "student" with the attributes given below(img)
Here I'm creating a database called "db" and a table name "student" with the attributes given below
![db1](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/db1.jpg?raw=true)
![db2](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/db2.jpg?raw=true)

## Step 4: Configure Hibernate

1. In Eclipse, create a Hibernate configuration file (e.g., `hibernate.cfg.xml`).
2. Add the necessary configurations to the file, including the database URL, username, and password.(img)
2. Add the necessary configurations to the file, including the database URL, username, and password.
![configxml](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/configxml.jpg?raw=true)

We set the property named "hibernate.show_sql" to true so that whenever we perform some operations on the database using Hibernate it shows the respective sql equivalent command in the output

## Step 5: Create Entity Class

1. Create a Java class that represents the entity you want to map to the database table.
2. Use `javax.persistence` annotations such as `@Entity`, `@Id`, and `@Column` to define the mapping.(img)
2. Use `javax.persistence` annotations such as `@Entity`, `@Id`, and `@Column` to define the mapping.

![entityclass](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/entityclass.jpg?raw=true)

Here I have created a class called "student" with three attributes roll(int),name(String),age(int).I have used @Entity before class and @Column before every attributes and also specified their names that they have in sql database . And also I used @Id for the roll attribute because it is a primary key

Expand All @@ -57,15 +63,19 @@ Here I have created a class called "student" with three attributes roll(int),nam
## Step 6: Create Application Code

1. Create a Java class (e.g., `App`) to interact with Hibernate.
(img)

![app](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/app.jpg?raw=true)


We'll discuss about these things in detail in the future.For now just add these in your App class

Now you should see these results in your db
![inserted](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/inserted.jpg?raw=true)


# Congratulations 🎉
Congrats for creating your first hibernate app!!You did it!!
![congrats](https://github.com/giriharan13/HibernateBasics/tree/master/setup/images/congrats.jpeg?raw=true)



0 comments on commit fab9e49

Please sign in to comment.