Powered by Blogger.

Hibernate Configuration file (hibernate.cfg.xml) in Detail

>> Wednesday, June 15, 2011

Hibernate Configuration file for SQLyog.

Before configuring the properties of hibernate.cfg.xml we should mention the xml schema definitions of hibernate-configurations.The dtd defines the version and everything which is licensed.

To configure with database to our application we should give all the properties related to our database.The given properties of hibernate-configuration.

hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
connection.password
connection.pool_size
hibernate.dialect
show_sql
hibernate.hbm2ddl.auto


These are the minimum and compulsory properties to give in our cfg.xml file.

Every database having it's own driver class and url.Collect that depends on database and configure for it.

The username and password are of your current database you can use.

Connection pool size we should mention to increase the capacity of connections at runtime if more connectins required.

Dialect property tells which database we are using to interact with hibernate.The name of the Dialect .Hibernate community has given several dialect names based on different Databases.

They are:

    DB2 - org.hibernate.dialect.DB2Dialect
    HypersonicSQL - org.hibernate.dialect.HSQLDialect
    Informix - org.hibernate.dialect.InformixDialect
    Ingres - org.hibernate.dialect.IngresDialect
    Interbase - org.hibernate.dialect.InterbaseDialect
    Pointbase - org.hibernate.dialect.PointbaseDialect
    PostgreSQL - org.hibernate.dialect.PostgreSQLDialect
    Mckoi SQL - org.hibernate.dialect.MckoiDialect
    Microsoft SQL Server - org.hibernate.dialect.SQLServerDialect
    MySQL - org.hibernate.dialect.MySQLDialect
    Oracle (any version) - org.hibernate.dialect.OracleDialect
    Oracle 9 - org.hibernate.dialect.Oracle9Dialect
    Progress - org.hibernate.dialect.ProgressDialect
    FrontBase - org.hibernate.dialect.FrontbaseDialect
    SAP DB - org.hibernate.dialect.SAPDBDialect
    Sybase - org.hibernate.dialect.SybaseDialect
    Sybase Anywhere - org.hibernate.dialect.SybaseAnywhereDialect


The property is the mapping for our register table.

here i have configured the properties for SQLyog
 
<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

 <session-factory>

  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://192.168.1.101:3306/test</property>
  <property name="hibernate.connection.username">test</property>
  <property name="connection.password">test</property>
  <property name="connection.pool_size">10</property>
  <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
  <property name="show_sql">true</property>
  <property name="hibernate.hbm2ddl.auto">update</property>

  <mapping resource="com/javabynataraj/register/dao/pojos/RegisterUser.hbm.xml" />

 </session-factory>

</hibernate-configuration>


Reference Books:

Sams Teach Yourself SQL in 10 Minutes (3rd Edition)

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2014. All rights reserved.