Hibernate Configuration on Eclipse with Maven

Step 1: Download the latest software for hibernate configuration.

Step 2: Configure maven 3.2 in your  local environment and execute bellow command on console,this project will create into you user folder.


mvn archetype:generate -DgroupId=com.javawebtutor -DartifactId=HibernateExample -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false



Step 2: open the eclipse and create java project
     Go to à File  à import à Existing Maven Project



Step 2: Click next à finish, you will get bellow screen.


Step 3:Added jar dependencies into pom.xml

 <dependencies>
    <!-- MySQL connector -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>6.0.5</version>
    </dependency>
    <!-- Hibernate 5.2.6 Final -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.2.6.Final</version>
    </dependency>
  </dependencies>


Step 4: Create a Hibernate configuration file
Create an XML file hibernate.cfg.xml under /resources folder
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/JAVAWEBWORLD</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  </session-factory>

</hibernate-configuration>

Step 5 Then create sample example an execute it.

  See sample example on hibernate

No comments: