How to address Schema Migration for Dummies

  1. Be very clear in what your PersistentEntity (an entity that directly corresponds to a db table) is and separate it from your Business related entities that may or may not have one to one relationship with the tables. Ideally, Business Entities should be defined on a need basis, however PersistentEntities should be defined as soon as your schema / data model design is ready for the first iteration of development.
  2. Once you create entities, you will annotate these entities, and I haved shared an example of such entities. These annotations should follow JPA annotations standard and not Hibernate annotations, because that way you will avoid vendor lockin, and be following a standard. JPA is a standard developed by Java Community and has JSR (Java Specification Request) which is implemented by Hibernate, J2EE, TopLink or any other middle-tier OR implementation.
  3. Add Hibernate Synchronizer plugin to Eclipse (you can also use the schem exporter command line utility, which you will find docs on RedHat Hibernate website). I highly recommend using Eclipse plugin because it makes the process visual and easy to follow.
  4. Use Hibernate Sychronizer to Export the Schema based on the PersistentEntities, this will require you to configure your persistence.xml file, which is usually placed in the class path, inside a jar or directly under the class path  i can share some examples for demonstration.
  5. The schema exporter works by pointing to your data base instance and generating all the tables that you have defined as PersistentEntities, taking care of all the constraint definitions, indexes etc. Will share a sample of that too.
  6. What you now have is the v1 of your db. This is ready to be used in your application by defining DAO or Data Access Layer, which abstracts out the operations performed on PersistentEntities. Note: As long as you have a good abstraction around DAO, your persistent entities will mostly remain unchanged until you decide to add more columns or tables to your schema.
  7. Now for v2, if you are adding more tables and columns, you will start with modifying the PersistentEntities directly and adding news ones where required. Reminder: All the entity relationships are also defined using Annotations, as you already are aware, and hence adding new tables only requires some new relationship annotations to be added to exisinting entities if they are going to have a new relationship with the newly added entity.
  8. After you are happy with your v2 db schema design and PersistentEntities created thereof, you will point to your Development DB server and generated the new schema based db instance.
  9. In this step you will need to have a tool that can compare db instance v1 with db instance v2 and generate a migration script for the DDL part. For data that needs to be migrated, you will have to write your own migration scripts. Note: If you are using MySQL then you are lucky because MySQL Workbench has great tools for schema comparison and migration DDL auto generation.


package com.rishik.hibernate.entity;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

* This is an object that contains data related to the file table.
* table="file"

public class FileEntity implements Serializable {

public static String REF = "FileEntity";
public static String PROP_TYPE = "type";
public static String PROP_ID = "id";
public static String PROP_USER = "user";
public static String PROP_CONTENT = "content";
public static String PROP_WORKSPACE = "workspace";
public static String PROP_CREATED_DATE = "createdDate";
public static String PROP_LAST_EDITED_DATE = "lastModifiedDate";
public static String PROP_LAST_EDITED_BY = "lastModifiedBy";

// constructors
public FileEntity () {

* Constructor for primary key
public FileEntity (java.lang.Long id) {

* Constructor for required fields
public FileEntity (
java.lang.Long id,
java.lang.Long userId,
java.lang.Long workspaceId) {


protected void initialize () {}

private int hashCode = Integer.MIN_VALUE;

// primary key
private java.lang.Long id = 0L;

// fields
private UserEntity user;
private WorkspaceEntity workspace;
private java.lang.String content;
private java.lang.String type;
private java.util.Date createdDate;
private java.util.Date lastModifiedDate;
private UserEntity lastModifiedBy;

* Return the unique identifier of this class
* generator-class="native"
* column="file_id"
public java.lang.Long getId () {
return id;

* Set the unique identifier of this class
* @param id the new ID
public void setId (java.lang.Long id) { = id;
this.hashCode = Integer.MIN_VALUE;

* Return the value associated with the column: user_id
public UserEntity getUser () {
return user;

* Set the value related to the column: user_id
* @param user the user_id value
public void setUser (UserEntity user) {
this.user = user;

* @return
public WorkspaceEntity getWorkspace() {
return workspace;

* @param workspace
public void setWorkspace(WorkspaceEntity workspace) {
this.workspace = workspace;

* Return the value associated with the column: content
public java.lang.String getContent () {
return content;

* Set the value related to the column: content
* @param content the content value
public void setContent (java.lang.String content) {
this.content = content;

* Return the value associated with the column: type
public java.lang.String getType () {
return type;

* Set the value related to the column: type
* @param type the type value
public void setType (java.lang.String type) {
this.type = type;

* @return the createdDate
public java.util.Date getCreatedDate() {
return createdDate;

* @param createdDate the createdDate to set
public void setCreatedDate(java.util.Date createdDate) {
this.createdDate = createdDate;

* @return the lastModifiedDate
public java.util.Date getLastModifiedDate() {
return lastModifiedDate;

* @param lastModifiedDate the lastModifiedDate to set
public void setLastModifiedDate(java.util.Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;

* @return the lastModifiedBy
public UserEntity getLastModifiedBy() {
return lastModifiedBy;

* @param lastModifiedBy the lastModifiedBy to set
public void setLastModifiedBy(UserEntity lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;

public boolean equals (Object obj) {
if (null == obj) return false;
if (!(obj instanceof FileEntity)) return false;
else {
FileEntity pOFile = (FileEntity) obj;
if (null == this.getId() || null == pOFile.getId()) return false;
else return (this.getId().equals(pOFile.getId()));

public int hashCode () {
if (Integer.MIN_VALUE == this.hashCode) {
if (null == this.getId()) return super.hashCode();
else {
String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
this.hashCode = hashStr.hashCode();
return this.hashCode;

public String toString () {
return super.toString();


Attention Bibliophiles – Personal Cataloging has arrived!

I am a bibliophile. I love collecting books but over the last few years I stopped collecting books because I couldn’t manage them. I was loosing as many books as I was buying, so my library never grew beyond a certain number. I lost them because I would lend them to friends and forget to take them back or carelessly leave them at places from where not even God could retrieve them.

For the latter problem there was nothing much I could do. But thankfully for the former one I found this cool tool that I have started using.

Personal Book Cataloging, using Dekoh Books. You probably already know that I talking about a product that my company has built and it is fair on your part to assume that I am writing this article to sell an application that was built by my company. I won’t deny that, but that is not the only reason. Dekoh Books has indeed helped me catalogue my books and figure out which books are with my friends, which are with my family and which ones have I simply misplaced.


The best part about Dekoh books is that now I can even add books to my Wishlist so that whenever I get a chance to visit a good book store, I can simply go through my wishlist and find out which books are pending on my list.


There is another cool feature of this application. You can search for books through Web Service and add them to your Wishlist, which will enable you to fetch the ISBN number and a thumbnail image of the book’s cover so that when you go to buy that book, you don’t pick some other similar sounding book by mistake.

Some books that I found through Dekoh Books Search by Keyword are visible in the snapshot above which has three recommended books that I have been trying to find for years now.

Click to see my shared books. **

And you will get the idea.

To start using this application, all you gotta do is visit

** If it asks you user name and password, type the following "neoriz" & "dekoh123".

Gizmoz: Technology Innovation OR Wastage

Gizmoz gives you the facility to build a expressive animated face out of any frontal snap you would like to animate. A cool tool for kids, but I failed to see the importance of this tool in its current stage of evolution. It’s likely that We might get to see a better use case than the ones this website is advertising.

I feel the engineers behind this tool should take their skills, imagination and time more seriously.
Two points on Gizmoz –

It doesn’t really give you a well-finished animation.

You can’t use these animations on your answering machines and be takenly seriously by the caller. Besides, I didn’t understand why do you need an animation for your answering machine.

Buzz or Biz???

If you read my first post completely you might have noticed that I signed-off with an odd question.

Let’s see which comes first, the chicken or the egg?

You may call it a foresight, divine intervention or coming events cast shadow thing!

I am in fact struggling with a chicken or egg situation here. Y te presento, mi predicamento:

What comes first in today’s fast changing and hyperactive software industry.

The Buzz or The Biz?

For the uninitiated or intellectually challenged, What makes a product or service big in today’s effervescent market, the business proposition that a company offers or the buzz they manage to generate?

It took me nearly 6-7 years to realize what Google was offering through their search engine was nearly unparalleled by anybody before or after. I have been reading many websites talking about semantic webs and specialized searches for different type of resources that are search candidates. But, there is no other Google when it comes to finding something on the internet. And yet I started using the term Google as a verb “Did you Google for xyz?” instead of a noun “Did you search for xyz on Google?” just about a year back. So Google-ing has become synonymous to searching stuff on internet. And on a personal level, I feel any product that becomes synonymous to an activity in our day to day lives, has created a “Buzz” or has become a “Buzz”.

So, in Google’s case, Buzz came after Biz. Yet sometimes Buzz comes before Biz. Like an Apple iPhone. As far as end users like me are concerned, all we know is that it is going to be something out of this world. And we like to believe that because Apple has established itself as a Style Icon in the world of technology for their elegant designs and catchy outfit. And the Buzz might in fact take iPhone’s sales to the sky even before people realized the limitations and drawbacks (if any). So, Apple’s iPhone might actually sell-off more pieces out of buzz than the real biz offerings.

This leads me to the profound question of Chicken or Egg? Or in my case Biz or Buzz???

I would bet my money on Biz. And yet I can’t ignore the strength of Buzz. I am working on creating a Buzz about a Biz. And let’s see which one yields better results for me…

Dekoh This!

Pramati launched Dekoh at Web2.0 Expo and we have been growing in our user base ever since. Here are some points you should know…

  • It is not a browser plug-in.
  • Yes! you have to install it on your computer but it takes less than 5 minutes for the framework installation on a high-speed network connection.
  • It is not the same thing as Google Gears or Adobe’s Apollo, it is very different and is more focused on bringing lay users the facility to host applications and content on their home computer, only for small scale web application hosting, social networking and collaboration.
  • Works out of a web browser, so no pain of learning how to operate on some new proprietary user interface.

Evaluate Dekoh, if you want all these things:

  1. Personal Hosting: A platform that enables you to build custom web applications to be used within your community and host them from your desktop.
  2. No-Upload Sharing: Want to share content with your friends, family and/or peer group without uploading any stuff anywhere.
  3. Personal Audio/Video Streaming Stations: You want to play music or videos stored at your home desktop anywhere in the world.
  4. Work Off line: You want to maintain to build an application that connects to Web Service, synchronize your local data store and then allows you to work on that data even when you are off line. (like in a basement, in flight, or while you are out camping.)

Benefits of working on Dekoh Platform:

  1. Open Source: You don’t have to pay anything but attention (to your idea)!
  2. Free Support: Our engineers will help you customize the platform (if you really need it), application support (for configuration and maintenance related issues).
  3. Creative Freedom: You can build almost any sort of application that needs a web server to run it. You imagination is your limit.
  4. Web 2.0 Toolkit: You can use our widgets and request for other components that are related to Web 2.0 to add flavor and flexibility to your and your community’s experience.
  5. Dev Kit: The best part about Dekoh is that a Dev Kit for building basic applications and deploying them takes under 30 seconds.
  6. Powerful Application Server: You will be leveraging the power of our enterprise application server, which has been condensed and made available to you for free with almost the same robustness, scalability and extensibility.
  7. API for extension: If you have some experience with extending API’s, you will know what we are talking about here. The potential to enhance the whole platform to your personal advantage with no cost involved.
  8. Be Trendy: It’s a cool app, which will make your desktop look cooler than before. The industry is moving towards offline web applications, and giants like Google and Adobe are the best benchmarks for understanding the trend.

Hello World – I am here!

There can’t be a more apt way of entering the Java world than “Hello World!”. Those magical words can transform about the most ordinary lives. At least for me they did.

I am relatively an infant in the Java world, but I am a precocious infant so I will say whatever I think is right and you have only two options, you agree with me or you die.

Java technology stack has grown from strength to strength in last decade and today it has reached a level of maturity that inspires confidence that the world could indeed depend on software. That intangible, quirky stuff some nerds keep punching in on their keyboards and that can do some wonderful stuff only we don’t know how it does that.

My ride through the software world allowed me to witness the prehistoric programmig languages like Fortran-77 and Pascal but as I moved ahead it has only gotten better with time.

In the life of a programmer, the real transformation occurs when one moves from straightforward procedural languages to the world of Object Oriented Programming, which kinda adds a realistic paradigm to the world of software. The complexity of objects in the real world and their relationships are translated verbatim in the OOPS world and that is when things start getting better. It’s like a boy turning into a man. Both the programmer and his code enter a new level of maturity and capability.

So, who am I? My name Rishik, and I would like to think it is a unique name, however it is no more. I have worked as a programmer for last 6 years now and worked on different sets of technologies. Currently, I am having an affair with Java Technology Stack. And I can’t express how rewarding this relationship has been right from its inception. I work with Pramati Technologies, and I have recently added another role to my portfolio, which is “Relationship Manager”. Apart from being a developer I am now into business development for half of my time. And I started this blog to bring out the lighter side of Java.

Let’s see what comes first, the chicken or the egg!