An eclipse plugin to automate Hibernate development

happy - baby

Yesterday I was digging a new pit, about Hibernate. It was very interesting to create the mapping xml files. But when number of table increases, when the table has many number of fields, it is highly error prone, time consuming. I was searching for an eclipse plugin to automate this, and found one.

http://salto-db.sourceforge.net/salto-db-generator/

Salto-db Generator is a faster and efficient plugin. They have a demo at their site as a SWF movie. That itself says about their quality of plugin.

Good work guys!

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 🙂