In the previous section we completed the database setup and created required table and populated with the data. In this section we will write required hibernate configuration files.
For this tutorial we need following Hibernate configuration files:
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:
"-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
Place hibernate.cfg.xml file in the source directory e.g. "C:\Struts-Hibernate-Integration\code\src\java"
The
Code of Tutorial.hbm.xml:
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> table="tutorials" > type="java.lang.Integer" column="id" > type="java.lang.String" column="shortdesc" not-null="true" length="50" /> type="java.lang.String" column="longdesc" not-null="true" length="250" /> type="java.lang.String" column="pageurl" not-null="true" length="100" /> |
Place Tutorial.hbm.xml file in the source directory e.g. "C:\Struts-Hibernate-Integration\code\src\java\roseindia\net\dao\hibernate\"
POJO Object
Here is the code of Java Bean object (Tutorial.java) used to store and retrieve the data from database.
package roseindia.net.dao.hibernate; |
In this section we have created all the Hibernate related stuffs.
0 comments:
Post a Comment