Magazine
 

Hibernate

 

and its associated attribute in the domain object. The <property> elements represent all other attributes available in the domain object.

The <generator> method is used to generate the primary key for the new record. Here is some of the commonly used generators:

  • Increment - This is used to generate primary keys of type long, short or int that are unique only. It should not be
    used in the clustered deployment environment.
  • Sequence - Hibernate can also use the sequences to generate the primary key. It can be used with DB2, PostgreSQL, Oracle, and SAP DB databases.
  • Assigned - Assigned method is used when application code generates the primary key.

IV. Hibernate Configuration File

Hibernate configuration file contains information that are essential to connect to persistent layer and the linked mapping documents.

In this application, Hibernate provides connection pooling and transaction management for simplicity. It uses the “hibernate.cfg.xml” Hibernate configuration file to create the connection pool and setup required environment. This file required either the Data Source Name or JDBC details to hibernate for making JDBC connection to the database. In this file we have given JDBC details.

Here is the code for hibernate.cfg.xml:

<?xml version=’1.0' encoding=’utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD//
EN”
“http://hibernate.sourceforge.net/hibernateconfiguration-
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.10.52/hibernatetutorial</property>
<property
name=”hibernate.connection.username”>root</
property>
<property
name=”hibernate.connection.password”>root</
property>
<property
name=”hibernate.connection.pool_size”>10</
property>
<property name=”show_sql”>true</
property>
<property
name=”dialect”>org.hibernate.dialect.MySQLDialect</
property>
<property
name=”hibernate.hbm2ddl.auto”>update</
property>
<!— Mapping files —>
<mapping resource=”contact.hbm.xml”/>
</session-factory>
</hibernate-configuration>

In the above configuration file we have specified the database “hibernatetutorial” which is running on server and the user of the database is root with its password.

The dialect property “org.hibernate.dialect.MySQLDialect” tells the Hibernate that we are using MySQL Database. Hibernate supports many database. We can use the following databases dialect type property to connect its related database:

  • 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
Dec  2007 | Java Jazz Up |30
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF