views:

300

answers:

2

Hi I am aware of the Hibernate Eclipse plugin that helps us (through a series of screens and button clicks) to generate the POJO and DAO classes for the underlying tables. But I would like to mimic this in a runtime environment, i.e. I would like to be able to do the exact same steps programmatically , where I should be able to supply the .cfg.xml file, the reveng.xml file, the database URL, the destination folder, via a command line/ parameters within main(String[] args)..

Apparently there is no such tool available which works in a pure Hibernate scenario. There is one which is tuned to generate code for the spring framework - but thats not of direct use to me right now.

I tried downloading hibernate-tools.jar's source code for the eclipse plugin, but right now the src code download link at hibernate.org(new design) has been disabled for some reason.

Has anyone handled such a thing before? Or can you give me some clues to do this?

I have tried a certain JDBCReader class's object, the rationale being read all tables using JDBCReader's methods and then figure out how to use hbm2POJO generator class....

+2  A: 

It appears there is an ant task to do this. You can call this ant task programatically by instantiating org.hibernate.tool.ant.HibernateToolTask and calling its execute() method. So you can either do this at compile-time or at run-time.

But I would advise against this. You haven't told use the scenario, but I don't think there are many reasonable scenarios for this.

Bozho
I agree with you, there are not many reasonable scenarios for this. I'm exploring this as one of many options by which the initial setup of my current web application project can be handled. Thanks for the lead. I will explore this.
Vatsala
+1  A: 

I would like to be able to do the exact same steps programmatically , where I should be able to supply the .cfg.xml file, the reveng.xml file, the database URL, the destination folder, via a command line/ parameters within main(String[] args)

The Hibernate Tools for Eclipse and Ant are usable from both Eclipse and Ant, respectively through an Eclipse plugin and through an Ant task and both share the same underlying classes that you can reuse "programmatically" (I'm not sure to understand what you're trying to do though).

I tried downloading hibernate-tools.jar's source code for the eclipse plugin, but right now the src code download link at hibernate.org(new design) has been disabled for some reason.

You can get Hibernate Tools sources from JBoss subversion repositories. More precisely, checkout the following project: http://anonsvn.jboss.org/repos/hibernate/trunk/HibernateExt/tools/. The classes you're looking for are in org.hibernate.tool.hbm2x.*.

Pascal Thivent
@Pascal Thivent Thank you for this. Frankly, I am not very happy with the idea of doing this either. but I have been instructed to find out how to do this, and hence this effort :)
Vatsala