Skip to content

Commit 5c3354f

Browse files
Merge branch 'main' into HHH-20302-fix-use-max-with-LocalDateTime
2 parents 8a4a37e + 76307ce commit 5c3354f

842 files changed

Lines changed: 67451 additions & 360 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.git-blame-ignore-revs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@
55
9c7dd3bf34dfbb2f4fa9eb79a0294c2cc759c836
66
b2a528f2945cee26667b22b867ccef143b7c430c
77
4273f1cde06f3622f50c2846078398c1977a49c4
8+
# Hibernate Tools merging
9+
05a9a8742e1684419ca4bcabcca060dc31048053
10+
3710fc0e8332992d7b87f66839dc489c4f46a8c8
11+
09f4af10843fc1d1e1dcd01d1f4856991fa8989d
12+
c7cc700acfe372cf6e67d7e60b021a8bf08360c6
13+
6acfbba01701d767065ed87207269d96adbdc52f
14+
bede74dc6f816065c78e31cd62ef16981dd90497
15+
75f4ce5d156e7987579eb32834667975d2d81ad4
16+
c448b6ba40c93c648b8d645d59ccf4bba55df567
17+
c57ae64b723fc6c7cb23a06a6b871869dca6ff3f
18+
9580fd1af50a637431a7a51242cdcb35aa3c0fe8

documentation/documentation.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ def jpaVersion = ormBuildDetails.jpaVersion
3939
defaultTasks 'buildDocs'
4040

4141
configurations {
42+
// hibernate-ant -> hibernate-reveng -> google-java-format -> guava
43+
// guava publishes JRE/Android variants that Gradle's reportAggregation
44+
// configuration cannot resolve; guava is not needed for report aggregation
45+
reportAggregation {
46+
exclude group: 'com.google.guava', module: 'guava'
47+
}
48+
4249
core
4350

4451
testing

documentation/src/main/asciidoc/userguide/chapters/tooling/Tooling.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ These services include
1414
* <<tooling-enhancement,Bytecode enhancement>>
1515
* <<tooling-modelgen,Static Metamodel generation>>
1616
* <<tooling-schema,Schema management>>
17+
* <<tooling-reveng,Reverse engineering>>
1718

1819
include::enhancement.adoc[]
1920
include::modelgen.adoc[]
2021
include::schema.adoc[]
22+
include::reveng.adoc[]
2123

2224
include::gradle.adoc[]
2325
include::maven.adoc[]

documentation/src/main/asciidoc/userguide/chapters/tooling/ant.adoc

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Hibernate provides https://ant.apache.org/[Ant] support.
55
Everything Ant related is available from the
66
https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-ant[hibernate-ant]
7-
library.
7+
library. The Ant integration supports <<tooling-ant-enhancement,bytecode enhancement>>,
8+
<<tooling-ant-modelgen,metamodel generation>>, and <<tooling-ant-reveng,reverse engineering>>.
89

910
[[tooling-ant-enhancement]]
1011
==== Bytecode Enhancement ====
@@ -192,6 +193,134 @@ Ant's https://ant.apache.org/manual/Tasks/javac.html[javac] task.
192193
====
193194

194195

196+
[[tooling-ant-reveng]]
197+
==== Reverse Engineering
198+
199+
Hibernate provides an Ant task for <<tooling-reveng,reverse engineering>> an existing database
200+
into Java entities, mapping files, DAOs, configuration files, and DDL scripts.
201+
202+
203+
[[tooling-ant-reveng-task]]
204+
===== Task Definition
205+
206+
The reverse engineering task is implemented by `org.hibernate.tool.ant.HibernateToolTask`.
207+
Define it in your `build.xml` using a `taskdef`:
208+
209+
[source,xml,subs="attributes+"]
210+
----
211+
<taskdef name="hibernatetool"
212+
classname="org.hibernate.tool.ant.HibernateToolTask"
213+
classpathref="toolslib"/>
214+
----
215+
216+
The `toolslib` classpath must include the
217+
https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-ant[hibernate-ant]
218+
artifact and its dependencies, as well as the JDBC driver for your database.
219+
220+
221+
[[tooling-ant-reveng-hibernatetool]]
222+
===== The `<hibernatetool>` Task
223+
224+
The `<hibernatetool>` task is the main entry point. It accepts the following attributes:
225+
226+
`destdir`:: The base output directory for generated files. Required (can be set on the task or on individual exporters).
227+
`templatepath`:: Path to a directory containing custom FreeMarker templates.
228+
229+
It also accepts `<property>` child elements for passing additional properties, and
230+
a `<classpath>` element for configuring the classpath.
231+
232+
233+
[[tooling-ant-reveng-configurations]]
234+
===== Configuration Elements
235+
236+
A `<hibernatetool>` task requires exactly one configuration element that defines how metadata is obtained.
237+
For reverse engineering from a database, use `<jdbcconfiguration>`:
238+
239+
`<jdbcconfiguration>`:: Reads database metadata via JDBC for reverse engineering. Attributes:
240+
+
241+
--
242+
`propertyfile`;; Path to a properties file containing JDBC connection settings.
243+
`configurationfile`;; Path to a `hibernate.cfg.xml` file.
244+
`packagename`;; The default Java package name for generated classes.
245+
`reversestrategy`;; Fully qualified class name of a custom reverse engineering strategy.
246+
`revengfile`;; Path containing reverse engineering configuration XML file(s) for customizing schema selection and type mappings.
247+
`detectmanytomany`;; Whether to detect many-to-many link tables. Default: `true`.
248+
`detectonetoone`;; Whether to detect one-to-one associations. Default: `true`.
249+
`detectoptimisticlock`;; Whether to detect `VERSION`/`TIMESTAMP` columns for optimistic locking. Default: `true`.
250+
--
251+
252+
Other configuration elements are also available for non-JDBC scenarios:
253+
254+
`<configuration>`:: Uses a `hibernate.cfg.xml` and/or HBM mapping files as input.
255+
`<jpaconfiguration>`:: Uses a JPA `persistence.xml` as input.
256+
257+
258+
[[tooling-ant-reveng-exporters]]
259+
===== Exporter Elements
260+
261+
One or more exporter elements can be nested inside `<hibernatetool>` to specify what artifacts to generate.
262+
Each exporter supports a `destdir` attribute to override the output directory.
263+
264+
`<hbm2java>`:: Generates Java entity classes.
265+
`<hbm2hbmxml>`:: Generates `hbm.xml` mapping files.
266+
`<hbm2dao>`:: Generates Data Access Object (DAO) classes.
267+
`<hbm2ddl>`:: Generates DDL scripts (schema creation/drop).
268+
`<hbm2cfgxml>`:: Generates a `hibernate.cfg.xml` configuration file.
269+
`<hbm2doc>`:: Generates HTML documentation of the database schema.
270+
`<hbmtemplate>`:: Runs a custom FreeMarker template for user-defined code generation.
271+
`<query>`:: Executes HQL queries against the configured metadata.
272+
273+
274+
[[tooling-ant-reveng-example]]
275+
===== Example
276+
277+
The following `build.xml` generates JPA entity classes from a database:
278+
279+
[source,xml,subs="attributes+"]
280+
----
281+
<project name="reveng-example" default="generate">
282+
283+
<path id="toolslib">
284+
<fileset dir="${lib.dir}">
285+
<include name="**/*.jar"/>
286+
</fileset>
287+
</path>
288+
289+
<taskdef name="hibernatetool"
290+
classname="org.hibernate.tool.ant.HibernateToolTask"
291+
classpathref="toolslib"/>
292+
293+
<target name="generate">
294+
<hibernatetool destdir="${build.dir}/generated-sources">
295+
<classpath>
296+
<path refid="toolslib"/>
297+
</classpath>
298+
<jdbcconfiguration
299+
propertyfile="src/main/resources/hibernate.properties"
300+
packagename="com.example.model"
301+
detectmanytomany="true"/>
302+
<hbm2java/>
303+
</hibernatetool>
304+
</target>
305+
306+
</project>
307+
----
308+
309+
To generate multiple artifact types in a single run, add additional exporter elements:
310+
311+
[source,xml]
312+
----
313+
<hibernatetool destdir="${build.dir}/generated-sources">
314+
<jdbcconfiguration
315+
propertyfile="src/main/resources/hibernate.properties"
316+
packagename="com.example.model"/>
317+
<hbm2java/>
318+
<hbm2dao/>
319+
<hbm2ddl/>
320+
</hibernatetool>
321+
----
322+
323+
195324
[[tooling-ant-schema]]
196325
==== Schema Management
197326

documentation/src/main/asciidoc/userguide/chapters/tooling/gradle.adoc

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[[tooling-gradle]]
22
=== Gradle
33

4-
Hibernate provides the ability to integrate both
5-
<<tooling-gradle-enhancement,bytecode enhancement>> and <<tooling-gradle-modelgen,metamodel generation>> capabilities into Gradle builds.
4+
Hibernate provides the ability to integrate
5+
<<tooling-gradle-enhancement,bytecode enhancement>>, <<tooling-gradle-modelgen,metamodel generation>>,
6+
and <<tooling-gradle-reveng,reverse engineering>> capabilities into Gradle builds.
67

78
[[tooling-gradle-enhancement]]
89
==== Bytecode Enhancement
@@ -29,7 +30,7 @@ hibernate {
2930

3031
Enhancement is configured through the `enhancement` extension.
3132

32-
NOTE: `hibernate {}` and `enhancement {}` are separate to allow for schema tooling capabilities to be added later.
33+
NOTE: `enhancement {}` and `reveng {}` are nested inside `hibernate {}` to configure different capabilities of the plugin.
3334

3435
[source,gradle]
3536
----
@@ -66,3 +67,104 @@ dependencies {
6667
annotationProcessor "org.hibernate.orm:hibernate-processor:{fullVersion}"
6768
}
6869
----
70+
71+
72+
[[tooling-gradle-reveng]]
73+
==== Reverse Engineering
74+
75+
The <<tooling-gradle-enhancement,Hibernate ORM Gradle plugin>> also provides
76+
<<tooling-reveng,reverse engineering>> capabilities to generate Java entities, mapping files,
77+
DAOs, configuration files, and DDL scripts from an existing database.
78+
79+
NOTE: The Gradle configuration cache must be disabled when using reverse engineering tasks.
80+
Add `org.gradle.configuration-cache=false` to your `gradle.properties` file.
81+
82+
83+
[[tooling-gradle-reveng-tasks]]
84+
===== Available Tasks
85+
86+
The plugin registers the following tasks:
87+
88+
`generateJava`:: Generates Java entity classes from the database schema.
89+
`generateDao`:: Generates Data Access Object (DAO) classes.
90+
`generateHbm`:: Generates `hbm.xml` mapping files.
91+
`generateCfg`:: Generates a `hibernate.cfg.xml` configuration file.
92+
`runSql`:: Executes the SQL statement specified by the `sqlToRun` extension property against the database.
93+
94+
95+
[[tooling-gradle-reveng-configuration]]
96+
===== Extension Configuration
97+
98+
Reverse engineering is configured through the `reveng` block inside the `hibernate` extension:
99+
100+
[source,gradle]
101+
----
102+
hibernate {
103+
reveng {
104+
hibernateProperties = 'hibernate.properties'
105+
outputFolder = 'generated-sources'
106+
packageName = 'com.example.model'
107+
generateAnnotations = true
108+
useGenerics = true
109+
}
110+
}
111+
----
112+
113+
The extension supports the following properties:
114+
115+
`hibernateProperties`:: Name of the properties file containing JDBC connection settings. The file is looked up from the project's main resource set. Default: `hibernate.properties`.
116+
`outputFolder`:: Relative path (from the project directory) where generated files are written. Default: `generated-sources`.
117+
`packageName`:: The default Java package name for generated classes. Default: empty (default package).
118+
`generateAnnotations`:: Whether to generate Jakarta Persistence annotations on entity classes. Default: `true`.
119+
`useGenerics`:: Whether to use Java generics in generated code. Default: `true`.
120+
`revengStrategy`:: Fully qualified class name of a custom reverse engineering strategy. Default: `null` (uses the default strategy).
121+
`revengFile`:: Name of a reverse engineering configuration XML file (looked up from the main resource set). Default: `null`.
122+
`templatePath`:: Path to a directory containing custom FreeMarker templates for code generation. Default: `null`.
123+
`sqlToRun`:: The SQL statement to execute when running the `runSql` task. Default: empty string.
124+
125+
126+
[[tooling-gradle-reveng-properties]]
127+
===== Hibernate Properties
128+
129+
Create a `hibernate.properties` file in `src/main/resources/` with your JDBC connection settings:
130+
131+
[source,properties]
132+
----
133+
hibernate.connection.driver_class=org.h2.Driver
134+
hibernate.connection.url=jdbc:h2:tcp://localhost/./mydb
135+
hibernate.connection.username=sa
136+
hibernate.default_catalog=MY_CATALOG
137+
hibernate.default_schema=PUBLIC
138+
----
139+
140+
The JDBC driver must be declared as a project dependency.
141+
142+
143+
[[tooling-gradle-reveng-example]]
144+
===== Example
145+
146+
The following `build.gradle` generates JPA entity classes from an H2 database:
147+
148+
[source,gradle,subs="attributes+"]
149+
----
150+
plugins {
151+
id 'java'
152+
id 'org.hibernate.orm' version '{fullVersion}'
153+
}
154+
155+
repositories {
156+
mavenCentral()
157+
}
158+
159+
dependencies {
160+
implementation 'com.h2database:h2:2.2.224'
161+
}
162+
163+
hibernate {
164+
reveng {
165+
hibernateProperties = 'hibernate.properties'
166+
packageName = 'com.example.model'
167+
outputFolder = 'generated-sources'
168+
}
169+
}
170+
----

0 commit comments

Comments
 (0)