{"id":29,"date":"2015-06-24T09:09:35","date_gmt":"2015-06-24T09:09:35","guid":{"rendered":"http:\/\/localhost\/tfcom_wp\/2015\/06\/24\/reverse-engineer-hibernate-objects\/"},"modified":"2025-06-30T02:31:58","modified_gmt":"2025-06-30T02:31:58","slug":"reverse-engineer-hibernate-objects","status":"publish","type":"post","link":"https:\/\/www.tech-freaks.com\/java\/jsp-servlets\/reverse-engineer-hibernate-objects.html","title":{"rendered":"Reverse Engineering Hibernate objects using JBoss eclipse plugin"},"content":{"rendered":"<p style=\"text-align: left;\">Writing hibernate class and xmls can be a pain, especially, if you have tons of tables in your database. One way to alleviate the pain is to use a reverse engineering tool, which would generate the xml and java files for hibernate by connecting to database. This article walks through the steps from installing the JBoss Tools Eclipse plugin to generate hibernate java and xml files.<\/p>\n<p><strong><span style=\"font-size: 12pt;\">Pre-requisites\u00a0<\/span><\/strong><\/p>\n<ul>\n<li style=\"text-align: left;\">MySQL and Eclipse are installed<\/li>\n<li style=\"text-align: left;\">MySQL has a database with at least one table<\/li>\n<li style=\"text-align: left;\">You have some basic knowledge about hibernate or any other ORM tool<\/li>\n<\/ul>\n<p style=\"text-align: left;\"><strong><span style=\"font-size: 12pt;\">Steps<\/span><\/strong><\/p>\n<p style=\"text-align: left;\"><span style=\"text-decoration: underline;\">Installing JBoss Eclipse Tools from marketplace<\/span><\/p>\n<p>Open Eclipse and follow the menu, Help -&gt; Eclipse Marketplace..<\/p>\n<p style=\"text-align: left;\">Search for &#8216;JBoss&#8217; or &#8216;Hibernate&#8217; and click install on the Jboss Tools<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/eclipse_marketplace_jboss.png\" alt=\"Eclipse Market Place\" width=\"700\" height=\"921\" \/><\/p>\n<p>Un-select all options except &#8220;Hibernate Tools&#8221; as shown in the below screenshot<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/jboss_hibernate_tools.png\" alt=\"JBoss tools install for Eclipse\" width=\"700\" height=\"921\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 700px; --smush-placeholder-aspect-ratio: 700\/921;\" \/><\/p>\n<p>Click &#8220;Confirm&#8221; and then &#8220;Finish&#8221;. Accept the license agreement.<\/p>\n<p>Eclipse will prompt to restart<\/p>\n<p style=\"text-align: left;\"><span style=\"text-decoration: underline;\">Creating the hibernate configuration (hibernate.cfg.xml)<\/span><\/p>\n<p>Once Eclipse has restarted, Open hibernate perspective. Windows -&gt; Open Perspective -&gt; Others<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/open_hibernate_perspective.png\" alt=\"Open Hibernate Perspective\" width=\"371\" height=\"474\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 371px; --smush-placeholder-aspect-ratio: 371\/474;\" \/><\/p>\n<p>The perspective will be empty. Click on the &#8220;Add Configuration&#8221; to start the configuration process, as shown below<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/hibernate_configurations.png\" alt=\"Hibernate Configurations\" width=\"1519\" height=\"817\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1519px; --smush-placeholder-aspect-ratio: 1519\/817;\" \/><\/p>\n<p>A window &#8220;Edit Configuration&#8221; will show up, as per the below screen shot. Select the Project by clicking Browse.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/hibernate_edit_config.png\" alt=\"Hibernate Edit Configuration\" width=\"700\" height=\"702\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 700px; --smush-placeholder-aspect-ratio: 700\/702;\" \/><\/p>\n<p>Next, click &#8220;Setup&#8221; from Configuration File section. This will open another windows as shown below.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/create_cfg_xml.png\" alt=\"Create hibernate.cfg.xml\" width=\"868\" height=\"779\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 868px; --smush-placeholder-aspect-ratio: 868\/779;\" \/><\/p>\n<p style=\"text-align: left;\">Using this, we will be creating the hibernate.cfg.xml which has the information like the database dialect, database URL, drivers, database type, db user id and db password. Once you click &#8220;Finish&#8221;, this will generate the hibernate.cfg.xml. Then click the &#8220;OK&#8221; in the &#8220;Edit Configuration&#8221; window should be open.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/rebuild_config.png\" alt=\"Rebuild Hibernate Config\" width=\"1519\" height=\"855\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1519px; --smush-placeholder-aspect-ratio: 1519\/855;\" \/><\/p>\n<p>Next, go to the Hibernate Configuration in the Hibernate perspective. Right click the new configuration which you added now and click &#8220;Rebuild Configuration&#8221;. You should now check the section under &#8220;Database&#8221; in the hibernate configuration.\u00a0 You should see the tables from your database. If the tables are not showing and it shows an error, you should not proceed further and resolve this issue first. Below are some possible reasons for the error<\/p>\n<ul>\n<li style=\"text-align: left;\">Database drivers are not in classpath:\u00a0\u00a0<span style=\"text-decoration: underline;\">Resolution<\/span>: Put the driver jar file in the WEB-INF\/lib folder to resolve this.<\/li>\n<li style=\"text-align: left;\">Database service is not started: <span style=\"text-decoration: underline;\">Resolution<\/span>: Start your database and try connecting again.<br \/>\nOne or more information entered in the hibernate.cfg.xml is incorrect. Verify all the information entered in the hibernate.cfg.xml, anything which is incorrect.<\/li>\n<li style=\"text-align: left;\">If you resolved the issue as explained above, you might want to &#8220;Rebuild Configuration&#8221; after resolving the issue.Once you can see the Database tables, you can proceed to the reverse engineering steps provided below.\n<p><span style=\"text-decoration: underline;\">Create a new Hibernate Reverse Engineering file<\/span><\/p>\n<p>From the Hibernate Perspective click &#8220;File&#8221; -&gt; &#8220;New&#8221; -&gt; &#8220;Hibernate Reverse Engineering File (reveng.xml)&#8221;<\/li>\n<\/ul>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/reveng_xml_step1.png\" alt=\"Create the reverse engineering file\" width=\"700\" height=\"671\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 700px; --smush-placeholder-aspect-ratio: 700\/671;\" \/><br \/>\nIn the Wizard that opens, select the project and click &#8220;Next&#8221;<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/reveng_xml_step2.png\" alt=\"Reverse Engineering Step 2\" width=\"700\" height=\"671\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 700px; --smush-placeholder-aspect-ratio: 700\/671;\" \/><\/p>\n<p>Select the &#8220;Console Configuration&#8221; from the drop down in the next step and click the &#8220;Refresh&#8221; button. The Database Schema section will show your database and tables. Select all the tables and click include. Click the &#8220;Finish&#8221; button to generate hibernate.reveng.xml file.<\/p>\n<blockquote><p>If you are unable to generate the hibernate objects, check that you have included all individual tables instead of the whole database and re-generate the reveng.xml<\/p><\/blockquote>\n<p style=\"text-align: left;\">Once you have the reverse engineering file generated, you need to do Run -&gt; Hibernate Code Generation -&gt; Hibernate Code Generation Configuration\u00e2\u201a\u00ac\u00a6<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/hibernate_code_generation_config.png\" alt=\"Hibernate Code Generation Configuration\" width=\"1519\" height=\"855\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1519px; --smush-placeholder-aspect-ratio: 1519\/855;\" \/><\/p>\n<p>In the window that opens, create a new configuration and enter details as per the below screenshot and click &#8220;Run&#8221;.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/hibernate_code_generation_config_main.png\" alt=\"Hibernate code generation main tab\" width=\"906\" height=\"702\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 906px; --smush-placeholder-aspect-ratio: 906\/702;\" \/><\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/hibernate_code_generation_config_exporters.png\" alt=\"Hibernate code generation exporters\" width=\"906\" height=\"702\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 906px; --smush-placeholder-aspect-ratio: 906\/702;\" \/><\/p>\n<p>Go back to Java EE perspective and you will see the hibernate xmls and java files generated in the package specified in the Main tab of the configuration before clicking Run.<\/p>\n<p>You might want to modify some of the content in the xml or java files generated as per your needs. However, remember that, if you have to regenerated the hibernate objects, your manual changes might get lost.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" data-src=\"https:\/\/www.tech-freaks.com\/wp-content\/uploads\/2015\/06\/add_mapping_cfg.png\" alt=\"Add Mapping to hibernate.cfg.xml\" width=\"1519\" height=\"817\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1519px; --smush-placeholder-aspect-ratio: 1519\/817;\" \/><br \/>\nOne last step you would need to perform, is to add the mapping of the bean in the hibernate.cfg.xml. Below shows a screenshot of adding one mapping.<\/p>\n<p style=\"text-align: left;\">That completes the steps to reverse engineer hibernate objects using JBoss Tools in Eclipse.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing hibernate class and xmls can be a pain, especially, if you have tons of tables in your database. One [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":16,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[10],"tags":[],"class_list":["post-29","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp-servlets"],"_links":{"self":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":2,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":139,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/29\/revisions\/139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/media\/16"}],"wp:attachment":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}