8

I'm upgrading an old project from hibernate3 to hibernate5. The project has a dependency on hbm2java (the so-called reverse engineering tool). In the old project this was executed with mvn hibernate3:hbm2java.

Unfortunately, hbm2java is nowhere to be found in Hibernate5 - not in the code, not in the documentation.

What is the Hibernate5 equivalent of the old hbm2java? Or in case it's no longer supported, what's the closest alternative? I'm willing to get out of Hibernate entirely, if that's what it takes to get out of Hibernate 3.

Alex R
  • 11,364
  • 15
  • 100
  • 180
  • What have you tried so far? Did you already try to pull and build the whole hibernate5 project in your local maven repo? – Jan Jul 12 '17 at 22:12
  • I tried `mvn hibernate5:hbm2java` and got the error: [ERROR] No plugin found for prefix 'hibernate5' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\xxxx.m2\repository), central (https://repo.maven.apache.org/maven2)] – Alex R Jul 12 '17 at 22:51
  • And prior to that you built the hibernate5 project from sources with mvn? – Jan Jul 13 '17 at 06:37
  • As stated in the question, I'm upgrading from hibernate3. So I didn't have a hibernate5 project. It was a hibernate3 project. And yes I built it with mvn. – Alex R Jul 14 '17 at 23:09
  • I meant, where did you install hibernate5 to? It is not in maven central (as seen by your error). Did you download the tarball or did you clone the latest version from git? – Jan Jul 17 '17 at 14:55
  • You can use hibernate5 as your runtime dependency and use hibernate3 for code generation. – user625488 Mar 17 '19 at 20:13
  • Check this out https://jonamlabs.com/how-to-use-hibernate-tools-maven-plugin-to-generate-jpa-entities-from-an-existing-database/ – Manoj Reddy Sep 02 '20 at 05:20

2 Answers2

3

The latest version of the hibernate-maven-plugin is 4.3.1.

You would get out of hibernate 3 by using hibernate 4.3.1 naturally.

It looks like the hbm2java task exists in the sources of the latest hibernate release: https://github.com/hibernate/hibernate-tools/blob/master/main/src/java/org/hibernate/tool/ant/Hbm2JavaExporterTask.java. That is what your were looking for isn't it? So it should also be possible to build the hibernate5 github project in your local maven repo and then bind the dependencies in your projects pom.

At last add the appropriate task and goal in your execution section.

Jan
  • 2,025
  • 17
  • 27
  • The code you found is for an Ant Task, from 2005, I don't think it's relevant to the problem at hand. – Alex R Jul 12 '17 at 22:54
  • The latest release of hibernate-tools is from April this year in version 5.2.3. But anyway you're probably right that the anttask is not relevant for the mvn execution. – Jan Jul 13 '17 at 06:38
2

Suggestion#1:

You can use maven ant runner. It may help.

mvn antrun:run@hbm2java

If you have modified templates (see the documentation) then, in pom.xml, modify the hibernate tool tag to look like:

<hibernatetool templatepath="src/the/path/to/the/directory/containing/pojo/directory">

The above path must point to the parent of the directory named pojo, containing your templates.

Also, if you have a custom reverse engineering strategy class the, in pom.xml add this attribute to jdbcconfiguration tag.

reversestrategy="fully.qualified.name.CustomDelegatingReverseEngineeringStrategy"

Resource Link: Hibernate tools reverse engineering using Maven

I haven't checked it but you can try with this procedure using Hibernate 5.X version.


Suggestion#2:

This issue seems critical in Hibernate 5.x version. All recommendation is to use 4.3 version for reverse engineering instead of 5.x

Resource Link: https://stackoverflow.com/a/37577315

Step by step tutorial to use 4.3 instead of 5.1 with pictorial view is given here: http://o7planning.org/en/10125/using-hibernate-tools-generate-entity-classes-from-tables

Some issues are given below:

  1. Database case-sensitive issue
  2. type mapping
  3. table filtering
  4. no <schema-selection> tag is specified

This issues is required to resolve by hand (it's just basic XML) or you can use the Hibernate plugins, which provides a specialized editor. http://www.hibernate.org/30.html

For reverse engineering rule, you can go through this tutorial: Chapter 6. Controlling reverse engineering

SkyWalker
  • 28,384
  • 14
  • 74
  • 132