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: http://download.jboss.org/jbosstools/updates/stable/helios/ and hibernate - http://download.jboss.org/jbosstools/updates/development
  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.

No comments:

Post a Comment