Generate hibernate model class single table

Generate hibernate model class single table

This tutorial will show you how to generate hibernate model class for single table . Sometimes when we join project in the middle then there won’t be choice go generate all model , mapping etc. file from the beging because most the files generated before. Based on the requirement if we will have to create separate table and generate model, mapping etc. files automatically and if you are not sure how to do it then you will start looking tutorial that could help you doing that. This tutorial probably help you to perform your task please follow below steps:

Generate hibernate model class single table – Tools needed:

  • Eclipse ( We are using eclipse Kepler)
  • Install JBoss tools in eclipse. If you are not sure how to install JBoss in eclipse please user this URL:Install JBoss tools in eclipse
  • MySQL data base (Install MySQL Community Server (GPL) version in your system : MySQL Community Server). We are using version 5.6

Configure hibernate

Steps:

  • Go to Hibernate perspective in eclipse. Click Run –> Click Hibernate code generation configuration as below:

Generate hibernate model class single table

  • It will open create, manage, and run configuration window
  • To generate model, mapping etc class for only one table or selected table. You will have to click Setup on reveng.xml block as below:

Generate hibernate model class single table

 

  • Once you click Setup it will ask you create a new reveng.xml or use an existing file. Click Create new…
  • Select project and file name then click Next:

Generate hibernate model class single table

 

  • Click Refresh button on configure table filters window.

Generate hibernate model class single table

 

  • Once you click Refresh button it will show you configured database schema. From above tutorial we have configured JavaHonk schema that shows to us. Expand schema it will show you table in it. Select the table name for which you want to generate files and include in table filters. For demo we have two table name address and person we will select address table for our demo as shown below:

Generate hibernate model class single table

 

  • Click finish. Now click Exporters tab and select what are exporters you want. We have checked two as below to generate corresponding files for it:

Generate hibernate model class single table

 

  • Now select output directory where you want to generate files and click Run as shown below:

Generate hibernate model class single table

 

  • It will start generating files for table you had chosen before. Now go to location which you had selected as output directory. For our demo we had src/main/resources folder there we will see generated file as below:

Generate hibernate model class single table

  • Generate hibernate model class single table – That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *