Magazine
 
Integrating Struts and Hibernate
 

Hibernate Configuration File Hibernate configuration file
(hibernate.cfg.xml) is used to provide the information which is necessary for making database connections. The mapping details for mapping the domain objects to the
database tables are also a part of Hibernate configuration file.

Here is the code of our Hibernate
Configuration File:

<?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:/
/localhost/struts-hibernate</property>
<property
name=”hibernate.connection.username”>root</
property>
<property
name=”hibernate.connection.password”></
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=”/roseindia/net/dao/
hibernate/Tutorial.hbm.xml”/>
</session-factory>
</hibernate-configuration>

 

Place hibernate.cfg.xml file in the source directory e.g. “C:\Struts-Hibernate- Integration\code\src\java”

The <mapping resource=’’> tag is used to specify the mapping file:

<mapping resource=”/roseindia/net/dao/
hibernate/Tutorial.hbm.xml”/>

Code of Tutorial.hbm.xml:

<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC “-//
Hibernate/Hibernate Mapping DTD//EN”
“http://hibernate.sourceforge.net/hibernatemapping-
3.0.dtd”>
<hibernate-mapping auto-import=”true”
default-lazy=”false”>
<class
name=”roseindia.net.dao.hibernate.Tutorial”
table=”tutorials”
>
<id
name=”id”
type=”java.lang.Integer”
column=”id”
>
<generator class=”increment” />
</id>
<property
name=”shortdesc”
type=”java.lang.String”
column=”shortdesc”
not-null=”true”
length=”50"
/>
<property
name=”longdesc”
type=”java.lang.String”
column=”longdesc”
not-null=”true”
length=”250"
/>
<property
name=”pageurl”
type=”java.lang.String”
column=”pageurl”

Dec 2007 | Java Jazz Up | 55
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