Create classes from database

I want to create the java classe from a given database.
I cannot setup a workflow that works for me. I’m not using eclipse and I don’t want to, I need a workflow that is easily reproducible if needed and does not require to install an entire IDE since i already use NetBeans.

I created a maven pom like this:

<?xml version="1.0" encoding="UTF-8"?> 4.0.0 com.mycompany MRPDBClassGenerator 1.0-SNAPSHOT jar
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
       <groupId>org.hibernate.orm</groupId>
       <artifactId>hibernate-core</artifactId>
       <version>6.4.4.Final</version>
   </dependency>       
</dependencies>
   
<build>
<plugins>       
  <plugin>
    <groupId>org.hibernate.tool</groupId>
    <artifactId>hibernate-tools-maven</artifactId>
    <version>6.4.4.Final</version>
    <dependencies>
      <dependency>
        <groupId>org.hibernate.tool</groupId>
        <artifactId>hibernate-tools-orm</artifactId>
        <version>6.4.4.Final</version>
      </dependency>
    </dependencies>
    <executions>
      <execution>
        <id>entity-generation</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>hbm2java</goal>
        </goals>
        <configuration>
          <ejb3>true</ejb3>
        </configuration>
      </execution>
    </executions>
  </plugin>      
</plugins>    

This is because I copied it somewhere, not because I found it on the Hibernate reference. (This is a first step towards depression).

At this point i tried to run the maven plugin the following way.

image

I’m not a maven expert: is a goal the same of a phase? Hope so. Netbeans is known to have a good maven integration but i find it rough. Perhaps if it presented me with the possible goals it would be clearer.

I also provided an Hibernate.properties file with connection information.

Now I get

Unknown lifecycle phase “entity-generation”. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. → [Help 1]

(really depressed now because I feel like a locksmith instead of a developer)

Can anyone point me in the right direction?

tnx in advance

Hey @Koen_Aers I think this one is for you.

Seems like @Koen_Aers hasn’t read the issue :smiley:

I’ll try to ping him again…

It’s not: Maven – Introduction to the Build Lifecycle

In this UI, though… maybe it is. I don’t know Netbeans.

I’d suggest you try to make it work on the command line first, then try to adapt what you get to the Netbeans UI.

This doesn’t match your screenshot… you’re asking netbeans to call generate-sources and are getting an error about entity-generation?

Anyway, entity-generation is the identifier of a goal execution (goal + configuration of that goal); it’s not a goal.

If you were to call this from the command line, I think you’d have to write something like this:

mvn org.hibernate.tool:hibernate-tools-maven:hbm2java@entity-generation

So I guess you can try putting org.hibernate.tool:hibernate-tools-maven:hbm2java@entity-generation in your Netbeans UI.

It seems slightly difficult to have this working here.
I resorted to install Eclipse. Brand new installation.
Then i tried to install JBoss Tools, version 4.29.1.
Only that in my neat environement.
It states that it’s going to install far more stuff that what I expected.
Anything as long as it works.
Result:


That infact was the only thing I needed. No reason provided. Besides reminding me why I hate eclipse and its ‘plugin architecture’, I wonder: how can I overcome this. Allow me to say that the conditions under which it works are pretty strict and ineffable.

Right now I’m implementing my own, simple reverse engineering tool :frowning:

Hello @agox, sorry for the very late reply…

There is a tutorial that shows how to use the Maven plugin right here: hibernate-tools/maven/docs/5-minute-tutorial.md at main · koentsje/hibernate-tools · GitHub

You need to use the ‘hbm2java’ goal. It should be possible to do that from NetBeans AFAIK

Regards,
Koen

I couldn’t have this tutorial working since I can’t find the artifact hibernate-tools-maven on the central repository.
(Don’t care about netbeans anymore as long as there is a way to have it working)

You can find the different versions of the Maven plugin right here: https://mvnrepository.com/artifact/org.hibernate.tool/hibernate-tools-maven

It builds but it does not generate anything.I’ve been stuck on this problem for too long now, I’m giving up, maybe I’ll try another orm that provides this out of the box. Also the paied support seems not so immediate so I think that my little expertise on this product makes this approach upractical right now. Maybe I’ll retry in the future.