Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto Generate hbm.xml from POJO

 
Sanket L Shah
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to migrate my application from JDBC to Hibernate. I have lots of POJO classes for that I have to create hbm.xml files. I want to know, Is there any way to generate hbm.xml and database table form POJO!?

For example.
I am having Student Pojo with setter and getter methods.


Is there any feature or plugin in Eclips to generate Student.hbm.xml and StudentTable (In Database) form [b]Student POJO/b]!?

Please help me!
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes, the JBoss Hibernate Tools plugin provides this option. After installation, right click on your POJO class in Eclipse and select New > Hibernate XML Mapping File.
However, note that the plugin really has no way of deciding column mappings. If your ID field is userID and column name is EMPLOYEE_ID, it can't really put in that
mapping - you need to do that manually.

For generating DDL, there are ant tasks and standalone tools that come along with Hibernate Tools. For DDL from POJOs, they need to be annotated. For DDL from XML mapping file, you have to use the ant task - hbm2ddl or something like that.

 
Sanket L Shah
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik Shiraly wrote:Hi,
plugin really has no way of deciding column mappings. If your ID field is userID and column name is EMPLOYEE_ID, it can't really put in that mapping - you need to do that manually.


Hi Karthik,
Thanks for your reply,You are right It does not generate column's mapping in generated hbm.xml file. Do you know any external tool for generating hbm.xml files form POJO?

Thanks for your reply!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic