Sunday, July 24, 2011


May you always have
Love to share,
Health to spare,
And friends that care.
got from a JIRA post 

Friday, July 22, 2011

Auto generating hibernate code using Eclipse (not my eclipse)

I hate using non-licensed tools. generally when it comes to code generation for Hibernate, pple tell of myeclipse; and heres the way to do it. Myeclipse usage requires licenses; so this is how pple get around it –uninstall it just before the trial expires and reinstall it again.

I hate all this crappy stuff and wanted a clean way to do it. I have used eclipse helios for this and guess it would work for other eclipse versions as well

  1. in eclipse help > install new software > give the url: and hibernate -
  2. say you added link 1, click on next and select all options then click on finish
  3. then redo the above for the link 2 aswell.

Now the hibernate plugin is installed. Below i tell the steps to auto genrate the code

  1. File > new > others > hibernate > new Hibgernate console configuration file
    1. select the project name, configurae a new db connection, property file, configuration files (all will take abt 1 min to complete)
  2. similarly do  File > new > others > hibernnate > new hingernate cfg.xml
  3. similarly do FIle > new others > hibernate > new reverse engineering file
    1. fill the step 1
    2. the step2 click on refresh after having selected the console configuration file in the dropdown
    3. select the table u r looking for
    4. incase ur table has foreign keys select the paret table also
    5. click on finish
  4. Inthe top bar (where u see save, print icos) u should see a new RunAs icon ( in black suffix)
    1. click on it you wil see a drop down
    2. select hibernate code generation configurations
    3. now double click on hiberante code generation (in the left tree)
    4. in the right side select consolef configuration
    5. select a temp directory, reverse engineering file we already created
    6. and say run; Bingo.. the code generation is done.

Now the qn: why did they build the plugin so complicated? why not have it a siimple one? all of it done in a wizard??? i donk know…

let me know if it helped you.

MySQL ERROR 1005 (HY000): Can't create table

Below is the table def that caused the problem:

  `source_col` int NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_src_col` (`source_col` ASC) ,
  CONSTRAINT `fk_src_col`
    FOREIGN KEY (`source_col` )
    REFERENCES `parent_table` (`id` )

and on execution it was giving the error ERROR 1005 (HY000): Can't create table schema.T_ABC.frm

The fix to issue is: that is of bigint type, while this table foreign key is only int; when i changed the source_col from int to big_int things went well.

hope this helps somebody.

Sunday, July 10, 2011

getHibernateTemplate().find() / query.list() returns list with null values

So the problem stmt is as follows

  1. The Entity primary key is mapped as composite-id in hbm files. i.e.. all columns/ multiple columns of the entity is taken as composite key. This gnerally happens when u use code generatoros. 
  2. now you say the below in criteria query
    Criteria criteria = getSession().createCriteria(CompositeKeyEntity.class);
    criteria = criteria.add("id.subKey", list));
    List<CompositeKey> list = criteria.list();

  3. The above returns a list with entities are null.

    1. why? Tracing the src code figured out that hibernate checks each of the values of primary keys. and when ever he finds one of the value as null doesn’t return the object. (org.hibernate.type.ComponentType.hydrate())
    2. This is logical as we shouldn’t have nulls in primary keys. But the problem is its not documented anywhere!

  4. so the fix: make all composite key columns as not-null; and give a default to each of the column.


Let me know if it helps.

Saturday, July 2, 2011

an email...

1) Heavy rains remind us of challenges in life.
Never ask for a lighter rain.
Just pray for a better umbrella.
2) When flood comes, fish eat ants & when flood recedes,
ants eat fish.Only time matters. Just hold on,
God gives opportunity to everyone!
3) Life is not about finding the right person,
but creating the right relationship, it is not how we care in the beginning, but how much we care till the ending.
4) Some people always throw stones in your path.
It depends on you what you make with them, Wall or Bridge? Remember you are the architect of your life.
5) Every problem has (n+1) solutions, where n is the number of solutions that you have tried and
1 is that you have not tried. That's life.
6) It is not important to hold all the good cards in life.
But it is important how well you play with the cards
which you hold.
7) Often when we lose all hope & think this is the end,
God smiles from above and says,'Relax dear, it is just a bend. Not the end. Have Faith and
have a successful life.
8) When you feel sad, to cheer up, just go to the mirror and say, 'Damn I am really so cute' and you will overcome your sadness.
But don't make this a habit because liars go to hell.
9) One of the basic differences between God and human is, God gives, gives and forgives. But human gets,
gets, gets and forgets. Be thankful in life!
10) Only two types of persons are happy in this world.
1st is Mad and 2nd is Child. 
Be Mad to achieve what you desire