Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions _config/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,9 @@ projects:
name: Hibernate Tools
icon: 'icon-wrench'
description: |
Working with Hibernate is very easy and developers enjoy using the APIs and the query language.
Even creating mapping metadata is not an overly complex task once you've mastered the basics.
Hibernate Tools makes working with Hibernate or JPA even more pleasant.
blog_tag: JBoss Tools
blog_tag_url: jboss-tools
Reverse engineer Java entities from an existing SQL database schema.
blog_tag: Hibernate Tools
blog_tag_url: hibernate-tools
license:
name: LGPL v2.1
url: https://github.com/hibernate/hibernate-tools/blob/master/lgpl.txt
Expand All @@ -400,23 +398,10 @@ projects:
- name: About
href: '/tools/'
css_class: 'home'
extern:
- name: Downloads
href: 'https://tools.jboss.org/downloads/'
css_class: 'cloud download'
- name: Documentation
href: 'https://tools.jboss.org/documentation/'
css_class: 'book'
#TODO add FAQ, Roadmap and Contribute page
#- name: FAQ
# href: '/search/faq/'
# css_class: 'circle help'
#- name: Roadmap
# href: '/search/roadmap/'
# css_class: 'road'
- name: Contribute
href: '/community/contribute/'
css_class: 'users'
extern:
- name: Source code
href: 'https://github.com/hibernate/hibernate-tools'
css_class: 'code'
Expand All @@ -429,9 +414,6 @@ projects:
- name: Forum
href: 'https://discourse.hibernate.org/c/hibernate-tools'
css_class: 'comments'
- name: Wiki
href: 'https://community.jboss.org/en/tools'
css_class: 'edit'
- name: CI
href: 'https://ci.hibernate.org/view/Tools/'
css_class: 'treatment'
Expand Down
Binary file added tools/images/reveng.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
187 changes: 163 additions & 24 deletions tools/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,182 @@ project: tools
-# Center body
.feature-block
:asciidoc
https://tools.jboss.org/features/hibernate.html[Hibernate Tools] is a toolset for Hibernate implemented as an integrated suite of
https://eclipseide.org[Eclipse] plugins,
together with a unified Ant task for integration into the build cycle.
Hibernate Tools is a core component of http://jboss.org/tools[JBoss Tools].
== Reverse Engineering from a Database

The following features are available within Eclipse.
.feature-block
:asciidoc
== Mapping Editor
Hibernate Tools is a set of build plugins and a Java library that can be used to generate Hibernate/JPA entities starting
from your relational database structure. The default behavior of the code generator is highly customizable via
XML or by plugging in custom generation strategies. In addition, other artefacts such as DAO classes, HTML
documentation, or even UI components can be generated by using and/or adding additional generation templates.
The API can be used from custom Java classes but is also readily usable in Maven, Gradle and Ant. Other
possibilities such as JBang and Quarkus are in the works.

An editor for Hibernate XML mapping files, supporting auto-completion and syntax highlighting.
The editor even supports semantic auto-completion for class names, property/field names, table names and column names.
image::/tools/images/reveng.png[Reverse Engineering]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really can be generated using the Maven/Ant/Gradle plugins? That's awesome.


image::https://static.jboss.org/hibernate/images/tools/hibernatetools_screen1.gif[Mapping editor]
.feature-block
:asciidoc
== Console
== Project Configuration

For the purpose of a quick introduction, let's assume that you have a database running, e.g.
https://github.com/maxandersen/sakila-h2[H2 Sakila database] reacheable at the following JDBC URL:
`jdbc:h2:tcp://localhost/./sakila`.

Let's assume as well that a `hibernate.properties` file below is available somewhere on the project's class path:

[listing]
hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila
hibernate.connection.username=sa
hibernate.default_catalog=SAKILA
hibernate.default_schema=PUBLIC

The Hibernate Console perspective allows you to configure database connections,
provides visualization of classes and their relationships
and allows you to execute HQL queries interactively against your database and browse the query results.
With this in place let's show some possible uses of the reverse engineering tooling to create Java classes from the
database.

image::https://static.jboss.org/hibernate/images/tools/hibernatetools_screen2.gif[Live HQL query editing]
.feature-block
:asciidoc
== Reverse Engineering
== Using the Maven Plugin

The Hibernate Tools Maven plugin can be used either directly or by configuration
in the `pom.xml` file of your project to generate entity classes or other artefacts. Let's assume you have created
a Maven project with the following `pom.xml` file.


[source, xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.bar</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<hibernate-core.version>${hibernate.version}</hibernate-core.version>
<h2.version>${h2.version}</h2.version>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-core.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>

</project>
----

Let's assume as well that the `src/main/resources` folder contains the `hibernate.properties` file shown earlier.

Having this in place simply issuing
[source]
-----
mvn org.hibernate.tool:hibernate-tools-maven:${hibernate.version}:hbm2java
-----
from a command line prompt in the project folder would use all the default settings to generate Java classes
for all the tables in `target/generated-sources/`.

[source]
-----
me@machine foo % ls target/generated-sources
Actor.java Film.java Inventory.java
Address.java FilmActor.java Language.java
Category.java FilmActorId.java Payment.java
City.java FilmCategory.java Rental.java
Country.java FilmCategoryId.java Staff.java
Customer.java FilmText.java Store.java
me@machine foo %
-----


Of course all these defaults can be overridden and tuned. Please consult the documentation for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine we don't have a link? 🙈

Suggested change
Of course all these defaults can be overridden and tuned. Please consult the documentation for more information.
Of course all these defaults can be overridden and tuned. Please consult https://some.link.org/foo[the documentation] for more information.


The most powerful feature of Hibernate Tools is a database reverse engineering tool
that can generate domain model classes and Hibernate mapping files, annotated EJB3 entity beans, HTML documentation
or even an entire JBoss Seam application in seconds!
.feature-block
:asciidoc
== Wizards
== Using Gradle Tasks

Let's assume in this case that we start off with a very simple default Gradle application, e.g. created with
`gradle init --type java-application --dsl groovy`.

With this setup, we replace the contents of the file `app/build.gradle` with the code below :

[source, groovy]
-----
plugins {
id('application')
id('org.hibernate.tool.hibernate-tools-gradle') version '${hibernate-tools.version}'
}

repositories {
mavenCentral()
}

dependencies {
implementation('com.h2database:h2:${h2.version}')
}
-----

As a last precondition, we make sure that the above `hibernate.properties` file is present in
folder `app/src/main/resources`.

With this in place, issuing
[source]
-----
gradle generateJava
-----
will use all the default settings to generate Java classes for all the tables in `app/generated-sources/`.

Several wizards are provided, including wizards to quickly generate Hibernate configuration (cfg.xml) files, and Hibernate console configurations.
.feature-block
:asciidoc
== Ant task
== Using Good Old Ant

Creating an Ant project is very simple. We only need a `build.xml` file to be present in the root of the project.
In order to manage the needed dependencies, the easiest way is to use the Ant tasks provided by Apache Ivy.

Our `build.xml` file will be looking like below:

[source, xml]
-----
<project xmlns:ivy="antlib:org.apache.ivy.ant">

<property name="hibernate.tools.version" value=the-hibernate-tools-version-to-use/>
<property name="h2.version" value=the-h2-version-to-use/>

<ivy:cachepath organisation="org.hibernate.tool" module="hibernate-tools-ant" revision="${hibernate.tools.version}"
pathid="hibernate-tools" inline="true"/>
<ivy:cachepath organisation="com.h2database" module="h2" revision="${h2.version}"
pathid="h2" inline="true"/>

<path id="classpath">
<path refid="hibernate-tools"/>
<path refid="h2"/>
</path>

<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="classpath" />

<target name="reveng">
<hibernatetool destdir="generated-sources">
<jdbcconfiguration propertyfile="hibernate.properties" />
<hbm2java/>
</hibernatetool>
</target>

</project>
-----

The Hibernate tools include a unified Ant task that allows you to run schema generation, mapping generation, or Java code generation as part of your build.
With the `hibernate.properties` file from above also present in the root of the project, simply issuing
[source]
-----
ant reveng
-----
would generate the Java files in the folder `generated-sources`.