Getting started with Hibernate

cute baby

I am trying to implement a demo with hibernate, for 6 months. Since I am not working with any hibernate, and because of my laziness too, I couldnt do that. Today I have taken some action to get it started.

This post will help you to insert and retrieve a value to/from a simple table using hibernate3

Dependencies:

1. Hibernate http://www.hibernate.org/
download the entire file and build it offline. Because we may need additional jars like xml, xerces etc along with hibernate.xml

2. MySql DB

3. MySql JDBC Driver http://dev.mysql.com/downloads/connector/j/5.1.html

4. If possible Eclipse to ease this assignment

TASK 1: DB PREPARATION

create a new db preferably, and create the following table

hibernate table structure

DROP TABLE IF EXISTS `hibernate`.`applabsuser`;
CREATE TABLE `hibernate`.`applabsuser` (
`USER_ID` int(11) NOT NULL default '0',
`USER_NAME` varchar(255) collate latin1_general_ci NOT NULL default '',
`USER_PASSWORD` varchar(255) collate latin1_general_ci NOT NULL default '',
`USER_FIRST_NAME` varchar(255) collate latin1_general_ci default NULL,
`USER_LAST_NAME` varchar(255) collate latin1_general_ci default NULL,
`USER_EMAIL` varchar(255) collate latin1_general_ci default NULL,
`USER_CREATION_DATE` date default NULL,
`USER_MODIFICATION_DATE` date default NULL,
PRIMARY KEY (`USER_ID`),
UNIQUE KEY `USER_NAME` (`USER_NAME`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

TASK 2: DTO PREPARATION

Please find the org.grassfield.User java file in the attached zip file.

To know about this step, please go thro the page http://www.allapplabs.com/hibernate/getting_started_with_hibernate_creating_pojo.htm

TASK 3: OBJECT TO DB HIBERNATE MAPPING DOCUMENT

Please find the org/grassfield/User.hbm.xml in the attached zip file

To know about this step, please go thro the page http://www.allapplabs.com/hibernate/getting_started_with_hibernate_mapping_pojo_with_persistence_layer%20.htm

TASK 4: HIBERNATE CONFIGURATION

Please find /hibernate.cfg.xml in the attached zip file

To know about this step, please go thro the page http://www.allapplabs.com/hibernate/getting_started_with_hibernate_configuration_file.htm

TASK 5:INSERTING AND QUERYING

Please find org.grassfield.TestHibernate and org.grassfield.TestHibernate2 for inserting and querying respectively.

I will be writing a loose sheet soon which may include detailed procedures. Hope this will be useful to just get started.

Attachment
hibernate demo source files

The picture given for this title is no way related to Hibernate, just to break the monotony 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s