-
Notifications
You must be signed in to change notification settings - Fork 48
HIB-129: Rework the Hibernate Tools landing page to reflect the actual situation #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine we don't have a link? 🙈
Suggested change
|
||||||
|
||||||
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`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.