Hibernate Mapping file #tutorial

In this small tutorial I am going to show you how hibernate mapping file is can be created when a SQL relation is given to you.

Let us say you have the following :

CREATE TABLE `feedback_feedback` (
`feedback_id` int(11) NOT NULL AUTO_INCREMENT,
`creator` int(11) NOT NULL,
`subject` varchar(255) COLLATE utf8_bin NOT NULL,
`content` varchar(5000) COLLATE utf8_bin NOT NULL,
`severity` varchar(25) COLLATE utf8_bin NOT NULL,
`comment` varchar(5000) COLLATE utf8_bin DEFAULT NULL,
`status` varchar(25) COLLATE utf8_bin DEFAULT NULL,
`date_created` date NOT NULL,
`date_changed` date DEFAULT NULL,
PRIMARY KEY (`feedback_id`)


and follwoing POJO :

package org.openmrs.module.feedback;

import java.util.Date;

Pojo file for feedback_feedback relation in Feedback Module

public class FeedbackFeedback  implements java.io.Serializable {

private Integer feedbackId;
private int creator;
private String subject;
private String content;
private String severity;
private String comment;
private String status;
private Date dateCreated;
private Date dateChanged;

Default no arguement constructor

public FeedbackFeedback() {

Constructor with all arguments

public FeedbackFeedback(int creator, String subject, String content, String severity, Date dateCreated) {
this.creator = creator;
this.subject = subject;
this.content = content;
this.severity = severity;
this.dateCreated = dateCreated;

Default constructor with arguments that can’t be Null

public FeedbackFeedback(int creator, String subject, String content, String severity, String comment, String status, Date dateCreated, Date dateChanged) {
this.creator = creator;
this.subject = subject;
this.content = content;
this.severity = severity;
this.comment = comment;
this.status = status;
this.dateCreated = dateCreated;
this.dateChanged = dateChanged;

public Integer getFeedbackId() {
return this.feedbackId;

public void setFeedbackId(Integer feedbackId) {
this.feedbackId = feedbackId;
public int getCreator() {
return this.creator;

public void setCreator(int creator) {
this.creator = creator;
public String getSubject() {
return this.subject;

public void setSubject(String subject) {
this.subject = subject;
public String getContent() {
return this.content;

public void setContent(String content) {
this.content = content;
public String getSeverity() {
return this.severity;

public void setSeverity(String severity) {
this.severity = severity;
public String getComment() {
return this.comment;

public void setComment(String comment) {
this.comment = comment;
public String getStatus() {
return this.status;

public void setStatus(String status) {
this.status = status;
public Date getDateCreated() {
return this.dateCreated;

public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
public Date getDateChanged() {
return this.dateChanged;

public void setDateChanged(Date dateChanged) {
this.dateChanged = dateChanged;

Now you want to create a Hibernate Mapping file for the above given relation then the hibernate mapping file will look somehow like this (explanation is given at the end for important elements) :

<?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 package=”org.openmrs.module.feedback” >
<class name=”org.openmrs.module.feedback.FeedbackFeedback” table=”feedback_feedback” >
<id name=”feedbackId” type=”java.lang.Integer”>
<column name=”feedback_id” />
<generator />
<property name=”creator” type=”int”>
<column name=”creator” not-null=”true” />
<property name=”subject” type=”string”>
<column name=”subject” not-null=”true” />
<property name=”content” type=”string”>
<column name=”content” length=”5000″ not-null=”true” />
<property name=”severity” type=”string”>
<column name=”severity” length=”25″ not-null=”true” />
<property name=”comment” type=”string”>
<column name=”comment” length=”5000″ />
<property name=”status” type=”string”>
<column name=”status” length=”25″ />
<property name=”dateCreated” type=”date”>
<column name=”date_created” length=”10″ not-null=”true” />
<property name=”dateChanged” type=”date”>
<column name=”date_changed” length=”10″ />

Comments :

1.      <class name=”org.openmrs.module.feedback.FeedbackFeedback” table=”feedback_feedback” >
This name element tells to which of the POJO class your relation is mapped , and table elements tells which relation you are currently referring to.

2.      <id name=”feedbackId” type=”java.lang.Integer”>
This tell which object in the class you are referring to and its data type. id tag tell it is a primary key.

3.       <column name=”feedback_id” />
This tell to which attribute in relation your class object will be mapped

4.       <generator />
This tell generator element tells how that element value will be generated.

5.       <property name=”severity” type=”string”>
This tell which object in the class you are referring to and its data type.This is just a atribute in table not a primary key.

For more detailed view see the official page : http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html

A Great Learning Curve

When I got access to SVN and become a new member of the ever growing OpenMRS community, I realized that I have full Read/Write access to whole of the SVN and asked my mentors following thing :


1. I want my write access to be "LIMITED" only to http://svn.openmrs.org/openmrs-modules/feedback/ . How this can be done ?

Then Burke Mamlin (My Co-Mentor) replied me with one of the best statement that I have heard so far :

"We purposefully don't try to manage a social problem (i.e., svn code of conduct) through a technical solution."

And then I realized the actual meaning of the fact that great power come with even greater responsibilities.Although the snip from the Burke's  mail is following :

Just limit your commits to that code.  If you check out that folder it will be very difficult – if not impossible – for you to accidentally write to other parts of the repository.  That said, if a couple months go by and you notice an obvious misspelling or typographical error in the code, you won't have to ask for privileges to change it.

We purposefully don't try to manage a social problem (i.e., svn code of conduct) through a technical solution.  You know what you should be doing & what you shouldn't be doing and we trust you.  If you make a mistake, the repository keep track of each change so it's very easy to fix.  If someone abuses their access to the repository, then that's easy to fix too. 🙂

Welcome to the family #openmrs

I requested the access to the repository by sending a mail at the Subversion Administrators <code_AT_openmrs_DOT_org> , and within some days once the module id conformed as the *feedback*, I got the access to SVN of OpenMRS with the mail from my own Mentor Ben Wolfe that states

"Welcome to the family!  You now have write access to the repository using the same credentials as you do for the wiki and jira sites. Please be sure to read about our repository conventions, including the code of conduct: ".

After that I gone through the Subversion Code of Conduct and http://openmrs.org/help/developers/#Subversion_Code_Repository as asked by the Ben Wolfe.At the same Ben's mail contain a quick small tutorial for the same which is following :

——(Snip from Ben Wolfe mail)—-

If you have already written your code, the easiest way to get your project into svn is using the "share project" link.

1) "Team–>Disconnect" your current project
2) Then "Team–>Share Project" your project
3) Specify a folder name (from the http://svn.openmrs.org repository) of "openmrs-modules/feedback/

trunk" as the directory name
4) Enter a commit comment like "Creating initial directory for feedback"
5) Choose "Team –> Commit" from the root of your project
(For some reason, this only adds the parent folder, so you'll have to now add all the files)
6) Choose "Team–>Commit" on the root of your project
7) Enter a commit comment like "Initial commit of all feedback files"

If you haven't written any code, the easiest thing to do would be to branch another module that you want to start from.  basicmodule, helloworldmodule, devexamples/simpleservicemodule are all good candidates.

1) Open the SVN Repository Exploring Perspective in Eclipse
2) Add http://svn.openmrs.org as a repository
3) Find the module you want to branch, right click on it and choose Branch/Tag
4) Enter http://svn.openmrs.org/openmrs-modules/feedback/trunk as the "Copy to URL"
5) Choose the "HEAD" revision
6) Enter a commit comment like "Initial commit of all feedback files"
7) Now do an svn checkout of that new trunk folder and start editing, adding, and then committing!

For all subsequent commits, choose "Team–>Commit" from the root of your project and check/uncheck the files that you want to send to the svn server.


On 2011-05-18 16:11:01 +0000 (Wed, 18 May 2011) , I have done my first commit to the OpenMRS repository although that was just a test before the actual work actually start. Although in a hurry I forgot to ignore the target folder which is then corrected with the help of a reminder from my mentor :). 

OpenMRS GSOC-2011 Community Bonding Period

My community bonding period with OpenMRS as a part of GSOC-2011 is going good.The project implementation ideas are almost completed that can be accessed here : https://wiki.openmrs.org/x/JQfn .And the concept of weekly developer call is really awesome : https://wiki.openmrs.org/display/docs/Weekly+Developer+Meeting .

Atlast made it to GSOC 2011, after previous year #rejection

In the morning when I wokeup on 26 April, 2011 , I saw the following mail, which says I am selected in #GSOC for 2011 through OpenMRS.


Dear Gaurav ,


Congratulations! Your proposal “General Feedback Mechanism” as submitted to “OpenMRS” has been accepted for Google Summer of Code 2011. Over the next few days, we will add you to the private Google Summer of Code Student Discussion List. Over the next few weeks, we will send instructions to this list regarding turn in proof of enrollment, tax forms, etc.

Now that you’ve been accepted, please take the opportunity to speak with your mentors about plans for the Community Bonding Period: what documentation should you be reading, what version control system will you need to set up, etc., before start of coding begins on May 23rd.


– – – – –