3:53 pm - Monday March 24, 4836

Hibernate configuration(cfg, hbm)

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044


<session-factory name=”studentFactory”>

Provides a unique name for property used with this database.

<property name=”connection.driver_class”> oracle.jdbc.OracleDriver </property>

The property connection.driver_class is used for loading database driver just like loading driver in JDBC(Class.forName();)

<property name=”connection.url”>jdbc:oracle:thin:@localhost:1521:XE </property>

Connection.url property is used to load connection for the paticular database

<property name=”connection.username”>system </property>

This property implies user name of the database.

“system”—This is default user name for oracle.

<property name=”connection.password”>system</property>

This property implies the database password.

system –Replace this with your oracle password.

<property name=”connection.pool_size”>5</property>

Connection.pool_size property is used to maintain connection pooling by application server not by the database server

<property name=”dialect”>org.hibernate.dialect.OracleDialect </property>

This is an optional property. which generates sql query for database based on the dialect we used. Different database have different query. Query may be change as the database changes. to over come this problem dialect come in exist.

<property name=”show_sql”>true</property>

This property displays sql query in console generated by the previous property dialect.

If it is false it doesn’t display the query.

<property name=”hbm2ddl.auto”>update</property>

Update–This Property Used to update the table Rather than create the new table.

If table already exists it update values into table otherwise it creates new table automatically.

Create–This property creates new table.

If the table already exists, it deletes all records in the table and create new table with the given values.

It’s better use update property rather than create to maintain old records.

<mapping resource=”com\\xml\\Student.hbm.xml”/>

Mapping Resource property is used for mapping pojo with table.

Be sure while com\\xml matches your package name else give your package name instead.

Hbm file:

hbm file is created for each pojo class.

It is used as mapping in hibernate.

It’s like an intermediate between hibernate java class and data base table.

All contents in this file are within hibernate mapping tag.




<class> tag is used for mapping a java class and table.

<class name=”POJOClassName” table=”tableName”>
 <id name="identifierName" type="DataType" column="ColumnName">
 <generator class="increment" />

IdentifierName — which should matches the member variable in java (pojo) class.

DataType – Should also matches the data type for the given variable in java class.

ColumnName – It may be any column name for table. It must be a primary key for the given table.

Increment – It’s optional. It automatically increases primary key value for the given table.

<property name=” identifierName ” type=” DataType ” column=” ColumnName ” />

Property tag is created for each identifier in the java class.


Filed in: Z-A Hibernate codes

No comments yet.

Leave a Reply