Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavaHibernate – Create Hibernate Configuration File with the Help of Plugin

Hibernate – Create Hibernate Configuration File with the Help of Plugin

Hibernate is a framework that provides some abstraction layer, meaning that the programmer does not have to worry about the implementations, Hibernate does the implementations for you internally like writing queries to perform CRUD operations, establishing a connection with the database, etc. It is a java framework that is used to develop persistence logic. More precisely Hibernate is an open-source, non-invasive, lightweight java ORM(Object-relational mapping) framework to develop objects which are independent of the database software and make independent persistence logic in all JAVA, JEE.

Hibernate requires understanding in advance, where to find the mapping information that defines how the Java classes relate to the database tables. It also requires a set of configuration settings related to the database. All such information is usually supplied as a standard Java properties file called hibernate.properties, or as an XML file named hibernate.cfg.xml. In this article Hibernate Example using JPA and MySQL we have seen that we have created an XML file inside the src > main > resources folder and named the file as hibernate.cfg.xml. We have configured all the properties for the MySQL Database something like that.

XML




<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
<hibernate-configuration>
    <session-factory>
  
        <!-- Set URL -->
        <property name = "hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate-demo(your schema name)</property>
  
        <!-- Set User Name -->
        <property name = "hibernate.connection.username">your MySQL user name</property>
  
        <!-- Set Password -->
        <property name = "hibernate.connection.password">your MySQL password</property>
  
        <!-- Set Driver Name -->
        <property name = "hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
  
        <property name = "hibernate.show_sql">true</property>
  
    </session-factory>
</hibernate-configuration>


So in this article, we are going to explain how can we create this configuration file with the help of a plugin. We don’t need to create this file manually.

Note: We are using STS(Spring Tool Suite) IDE for this installation.

Procedure:

  1. Open your STS IDE
  2. Go to the Help > Eclipse Marketplace
  3. search JBoss Tools and select the JBoss Tools 4.21.0.
  4. Click on the Install button.
  5. Deselect all and choose only the Hibernate Tools option.
  6. Click on Confirm button.
  7. Accept terms button
  8. Click on the Finish button.
  9. Create a new Maven project/ Choose some exciting projects.
  10. Choose the folder location
  11. Click on the Next button.
  12. In the Wizards box, search for the hibernate
  13. Click on Next
  14. At last click on the Finish button and you are done.

Step By Step Installation of Hibernate Helper Plugin

Step 1: Open your STS IDE, go to the Help > Eclipse Marketplace

Step 2: In the find box search JBoss Tools and select the JBoss Tools 4.21.0.Final, and click on the Install button. Just look at the installs count. 

Step 3: There is no need to install everything. Just deselect all and choose only the Hibernate Tools option. And click on Confirm button.

Step 4: After that choose the accept terms button and click on the Finish button. 

Now the plugin has been installed successfully. Now with the help of this plugin, we are going to create Hibernate Configuration File. 

Step 5: Now create a new maven project or choose some exciting project. In the resource folder, right-click and go to the New > Other.

Step 6: Then in the Wizards box, search for the hibernate and choose the Hibernate Configuration File (cfg.xml) option. And click on Next.

Step 7: After that choose the folder location (resource) and you can also change the configuration file name. Then click on the Next button.

Step 8: In this pop up choose your required database dialect and similarly choose your drier class and also provide your URL, Username, and Password. At last click on the Finish button and you are done.

You can see the configuration file has been generated and the corresponding property values have been set. 

RELATED ARTICLES

Most Popular

Recent Comments