Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Hibernate Mapping Files 
 

In this section I will describe you the necessary Hibernate Mapping Files that is required to develop a hibernate application.

 

Hibernate Mapping Files

                         

Hibernate Mapping Files:

In this section I will describe you the necessary Hibernate Mapping Files that is required to develop a hibernate application. Hibernate is very flexible O/R mapping tool. It works with many databases and it's very easy to move the application from one database to another database.

Hibernate is configured at two levels:

  1. Hibernate service
  2. Persistence class configuration

Hibernate Service configuration

To configure the Hibernate service usually hibernate.cfg.xml file is used. The default name of configuration file is hibernate.cfg.xml, but it is also possible to give different name to the configuration file.

While configuring the Hiberbate Service we provide database connection url and passwords. We also provide different caching level for the application performance.

Here is the code of hibernate.cfg.xml file used in our example application

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD//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://localhost:3306/hibernatemappings</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="employee.hbm.xml"/>

</session-factory>

</hibernate-configuration>

Configuration parameter description:

hibernate.connection.driver_class is used to specify the JDBC Driver class

hibernate.connection.url is database connection url

hibernate.connection.username is username to access database

hibernate.connection.password is the password to connect to the database

dialect property is used to specify the database dialect. Here in this case it is org.hibernate.dialect.MySQLDialect. You can read more about hibernate dialect here.

Configuring the Persistence class

Usually <persistence-object>.hbm.xml file is used to configure the Persistence object. Here is the example employee.hbm.xml configuration used in our application.

employee.hbm.xml

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="roseindia.Employee" table="employee">

<id name="empId" type="int" column="Emp_id" unsaved-value="0">

<generator class="increment"/>

</id>

<property name="empName" type="java.lang.String" column="Emp_name" not-null="true" length="50" />

<property name="empSal" type="java.lang.Double" column="Emp_sal" not-null="true" />

</class>

</hibernate-mapping>

In nutshell we need one configuration file and one hibernate mapping files to develop the application. These are:

  • hibernate.cfg.xml and
  • <persistence-object>.hbm.xml

                         

» View all related tutorials
Related Tags: c database flex hibernate file files data ui application mapping io map this tool oo app tab move ping with

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.