Skip to content

Instantly share code, notes, and snippets.

@somecuitears
Last active June 22, 2017 13:36
Show Gist options
  • Save somecuitears/d57fbf2a9ed06964c1abcef0989718cd to your computer and use it in GitHub Desktop.
Save somecuitears/d57fbf2a9ed06964c1abcef0989718cd to your computer and use it in GitHub Desktop.
Hibernate Configuration with Spring

Hibernate Configuration

Create Spring MVC project

  1. Click on Project root and Add Framework Support... or download Hibernate_release.zip(ORM) from http://hibernate.org
  2. Click Hibernate from list and Select download and ok
  3. Open Module Setting and inside Modules select hibernate and add configuration file "hibernate.cfg.xml"
  4. The hibernate configuration file will be added to src > resources. Open the file and paste the following codes if you are using MYSQL database
        <session-factory>
               <!-- Database connection settings -->
               <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
               <property name="connection.url">jdbc:mysql://localhost:3306/**DATABASE_NAME**</property>
               <property name="connection.username">root</property>
               <property name="connection.password"></property>
       
               <!-- JDBC connection pool (use the built-in) -->
               <property name="connection.pool_size">5</property>
       
               <!-- SQL dialect -->
               <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
       
               <!-- Echo all executed SQL to stdout -->
               <property name="show_sql">true</property>
       
               <!-- Drop and re-create the database schema on startup -->
               <property name="hbm2ddl.auto">create</property>
              
               <!--For existing database-->
               <!--<property name="hbm2ddl.auto">validate</property>-->
                       
               <!-- Names the annotated entity class -->
               <mapping class="com.**Location.to.Model**"/>
       
           </session-factory>
  5. Change Database name and Location to Model
  6. Download Mysql-connector jar file from https://mvnrepository.com/artifact/mysql/mysql-connector-java
  7. Place it inside lib folder (Both Compile and Runtime Lib) and add it to the library.
  8. Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment