Skip to content

Commit 0c5dda4

Browse files
committed
* Global XML binding
* Design doc cleanup
1 parent cfb8a4f commit 0c5dda4

21 files changed

Lines changed: 921 additions & 45 deletions

design/annotation-xml-coverage-triage.adoc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ current Hibernate ORM annotation binding.
2121
* `@Parent`
2222
* `@PartitionKey`
2323
* `@RowId`
24-
* `@SecondaryRow`
25-
* `@SoftDelete`
26-
* `@TenantId`
2724
* `@TimeZoneStorage`
2825
* `@TimeZoneColumn`
2926
* `@CreationTimestamp`
@@ -70,3 +67,13 @@ ordinary Java annotations.
7067
whether to repurpose it for XML/dynamic-model use or define a replacement.
7168

7269

70+
== Resolved / Covered Locally
71+
72+
These items have local implementation and focused test coverage, so they should
73+
not be treated as open triage items unless a later parity audit finds a narrower
74+
gap.
75+
76+
* `@SecondaryRow`
77+
* `@SoftDelete`
78+
* `@TenantId`
79+

design/new-contributor-model-binding-guide.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ Touchpoint:
144144
The record has convenience factories for the source forms used by the PoC:
145145

146146
* `AvailableResources.from(PersistenceUnitDescriptor, AvailableResourcesContext)`
147+
* `AvailableResources.from(PersistenceUnitDescriptor, AvailableResourcesContext, ResolvedBootstrapSettings)`
147148
* `AvailableResources.from(PersistenceConfiguration, AvailableResourcesContext)`
148149
* `AvailableResources.from(HibernatePersistenceConfiguration, AvailableResourcesContext)`
149150
* `AvailableResources.from(HibernatePersistenceConfiguration, AvailableResourcesContext, ResolvedBootstrapSettings)`
151+
* `AvailableResources.from(BootstrapSourceContributions, AvailableResourcesContext, ResolvedBootstrapSettings)`
150152
* `AvailableResources.from(MetadataSources, AvailableResourcesContext)`
151153

152154
link:../src/main/java/org/hibernate/boot/models/source/AvailableResourcesContext.java[`AvailableResourcesContext`]

design/orm-bootstrap-direction.adoc

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
This note captures the proposed direction for using this PoC to replace and simplify large parts of ORM bootstrap,
55
especially the JPA path through `EntityManagerFactoryBuilderImpl`.
66

7+
[NOTE]
8+
====
9+
This is an early, historical direction note.
10+
11+
The distilled current target is captured in
12+
link:session-factory-bootstrap-design.adoc[`session-factory-bootstrap-design.adoc`],
13+
and ongoing implementation status lives in
14+
link:session-factory-bootstrap-plan.adoc[`session-factory-bootstrap-plan.adoc`].
15+
====
16+
717
== Current ORM Shape
818

919
From the JPA side, `EntityManagerFactoryBuilderImpl` currently handles several phases inline:
@@ -39,19 +49,18 @@ JpaBootstrapSettings
3949
BootstrapSourceContributions
4050
AvailableResources
4151
CategorizedDomainModel
42-
BoundMetadata
52+
ResolvedMetadata
4353
----
4454

4555
The intended flow is:
4656

4757
[source]
4858
----
4959
PersistenceUnitDescriptor / HibernatePersistenceConfiguration
50-
-> JpaBootstrapSourceCollector
5160
-> BootstrapSourceContributions
5261
-> AvailableResources
5362
-> DomainModelCategorizer
54-
-> BindingCoordinator
63+
-> BindingCoordinator / MetadataResolver
5564
----
5665

5766
== Settings
@@ -83,7 +92,7 @@ Inputs:
8392
* persistence-unit class names
8493
* mapping file names
8594
* standard `META-INF/orm.xml`
86-
* explicit `HBM_XML_FILES`
95+
* [.line-through]#explicit `HBM_XML_FILES`#
8796
* scanner results
8897
* loaded classes
8998
* packages
@@ -101,8 +110,11 @@ It should contain:
101110
* resolved `ClassDetails` for managed classes
102111
* resolved package-info `ClassDetails`
103112
* XML bindings
104-
* dynamic model names/classes if needed
105-
* possibly extra query imports, either directly or as a sibling object
113+
114+
Dynamic model names/classes are discovered during XML processing rather than
115+
stored as separate `AvailableResources` buckets. Extra query imports should be
116+
represented explicitly by the caller/test infrastructure rather than folded into
117+
`AvailableResources`.
106118

107119
It should not contain merged settings.
108120

@@ -112,16 +124,8 @@ should be source-model oriented and normalized for categorization.
112124

113125
== XML Preprocessing
114126

115-
Move XML preprocessing behind `AvailableResources`.
116-
117-
The short-term adapter is acceptable:
118-
119-
[source]
120-
----
121-
AvailableResources -> ManagedResources adapter -> XmlPreProcessor
122-
----
123-
124-
The intended direction is direct consumption:
127+
Move XML preprocessing behind `AvailableResources`. The PoC now uses direct
128+
consumption:
125129

126130
[source]
127131
----
@@ -134,7 +138,7 @@ Categorization should consume normalized resources:
134138

135139
[source]
136140
----
137-
AvailableResources + BootstrapContext -> CategorizedDomainModel
141+
AvailableResources + MetadataBuildingContext -> CategorizedDomainModel
138142
----
139143

140144
This replaces the current ad hoc categorization work in `MetadataBuildingProcess.processManagedResources(...)`.
@@ -240,7 +244,7 @@ This is where the PoC’s DomainModelCategorizer belongs.
240244

241245
[source]
242246
----
243-
(AvailableResources + BootstrapContext) -> CategorizedDomainModel
247+
(AvailableResources + MetadataBuildingContext) -> CategorizedDomainModel
244248
----
245249

246250
This replaces the current ad hoc collection in MetadataBuildingProcess.processManagedResources(...).
@@ -274,23 +278,26 @@ AvailableResources should be normalized:
274278
* no setting merge concerns
275279

276280

277-
== Next PoC Slice
281+
== Historical PoC Slice
278282

279-
Prototype this chain:
283+
The original next slice was:
280284

281285
[source]
282286
----
283287
PersistenceUnitDescriptor / HibernatePersistenceConfiguration
284-
-> JpaBootstrapSourceCollector
288+
-> BootstrapSourceContributions
285289
-> AvailableResources
286290
-> DomainModelCategorizer
287291
----
288292

289-
Do not wire binding yet.
293+
That slice is now covered locally and binding has also been wired through
294+
`MetadataResolver`. Keep this section only as historical context for how the
295+
source/categorization work was first isolated.
290296

291-
The test target should be:
297+
The original test target was:
292298

293299
* Given JPA bootstrap inputs, the PoC derives the same available classes, packages, XML, and global registrations
294300
that ORM currently derives through `EntityManagerFactoryBuilderImpl` and `ManagedResources`
295301

296-
This establishes a clean replacement boundary before touching binder and persister integration.
302+
That established the source/categorization replacement boundary before the PoC
303+
moved on to binder and SessionFactory integration.

design/remaining-binding-gaps.adoc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,42 @@ Prototype touchpoints:
107107

108108
== Global Registrations and Named Objects
109109

110+
Recently covered:
111+
112+
* XML persistence-unit/global named query collection.
113+
+
114+
Entity-level XML named queries are processed by ORM's XML model processor into
115+
annotation usages on the affected `ClassDetails`, and the current categorizer
116+
collects those annotation usages. Root-level `<named-query/>`,
117+
`<named-native-query/>`, and `<named-stored-procedure-query/>` declarations live
118+
directly under `<entity-mappings/>`; these are now collected into the same
119+
global named-query registration maps.
120+
* XML `sql-result-set-mapping` collection.
121+
* XML HQL import collection from root-level `<import/>`.
122+
* XML database object collection from root-level `<database-object/>`.
123+
* XML fetch profile collection from root-level `<fetch-profile/>`.
124+
* Binding XML `sql-result-set-mapping` registrations into the metadata product.
125+
* Binding XML database object registrations into the metadata product.
126+
* Binding XML fetch profile registrations into the metadata product.
127+
110128
Known remaining gaps:
111129

112-
* XML named query collection/binding.
113-
* XML named entity graph collection/binding.
130+
* XML entity graph collection/binding should distinguish two cases:
131+
+
132+
Entity-level XML graphs are processed into annotation usages on `ClassDetails`.
133+
Those annotation usages are collected, but the collected graph definition still
134+
uses a placeholder runtime creator. If XML ever grows root-level graph
135+
declarations, they would need the same explicit root-level collection path as
136+
named queries.
114137
* Runtime graph creator integration for collected named entity graphs.
115138

116139
Prototype touchpoints:
117140

118141
* link:../src/main/java/org/hibernate/boot/models/categorize/internal/DomainModelCategorizationCollector.java[`DomainModelCategorizationCollector`]
119142
* link:../src/main/java/org/hibernate/boot/models/categorize/spi/GlobalRegistrations.java[`GlobalRegistrations`]
120143
* link:../src/main/java/org/hibernate/boot/models/categorize/spi/NamedQueryRegistration.java[`NamedQueryRegistration`]
144+
* link:../src/main/java/org/hibernate/boot/models/bind/spi/BindingCoordinator.java[`BindingCoordinator`]
145+
* link:../src/main/java/org/hibernate/boot/models/bind/spi/MetadataCollector.java[`MetadataCollector`]
121146

122147

123148
== Annotation and XML Coverage Triage

design/session-factory-bootstrap-plan.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,8 +2092,6 @@ ResolvedBootstrapSettings + BootstrapSourceContributions + ServiceRegistry
20922092
-> CategorizedDomainModel (*)
20932093
-> BindingState (*)
20942094
-> MetadataCollector
2095-
-> order columns
2096-
-> validate
20972095
-> MetadataImplementor (*)
20982096
-> ResolvedMetadata
20992097
----
@@ -2112,6 +2110,12 @@ state. It intentionally does not carry `ResolvedBootstrapSettings`; settings
21122110
remain input to metadata resolution and to later settings resolvers, not part of
21132111
the metadata result.
21142112

2113+
At the moment `MetadataResolver#finalizeMetadata` builds ORM's finalized
2114+
`MetadataImpl` through `InFlightMetadataCollectorImpl#buildMetadataInstance`.
2115+
Column ordering and validation are exercised by binding tests, but they are not
2116+
yet permanently owned by `MetadataResolver`; that remains one of the follow-up
2117+
questions above.
2118+
21152119
Later slices should add one resolver per gross target rather than growing a
21162120
single SessionFactory-wide orchestrator.
21172121

src/main/java/org/hibernate/boot/models/bind/internal/BindingStateImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
1313
import org.hibernate.boot.model.NamedEntityGraphDefinition;
1414
import org.hibernate.boot.model.convert.spi.RegisteredConversion;
15+
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
1516
import org.hibernate.boot.model.naming.Identifier;
1617
import org.hibernate.boot.model.relational.Database;
1718
import org.hibernate.boot.models.bind.internal.binders.AssociationTableBinding;
@@ -37,6 +38,7 @@
3738
import org.hibernate.boot.models.categorize.spi.FilterDefRegistration;
3839
import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata;
3940
import org.hibernate.boot.models.categorize.spi.ManagedTypeMetadata;
41+
import org.hibernate.boot.query.NamedResultSetMappingDescriptor;
4042
import org.hibernate.boot.spi.MetadataBuildingContext;
4143
import org.hibernate.engine.jdbc.spi.JdbcServices;
4244
import org.hibernate.engine.spi.FilterDefinition;
@@ -46,6 +48,7 @@
4648
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
4749
import org.hibernate.metamodel.mapping.JdbcMapping;
4850
import org.hibernate.mapping.Collection;
51+
import org.hibernate.mapping.FetchProfile;
4952
import org.hibernate.mapping.Join;
5053
import org.hibernate.mapping.MappedSuperclass;
5154
import org.hibernate.mapping.PersistentClass;
@@ -164,6 +167,26 @@ public void addNamedEntityGraph(NamedEntityGraphDefinition namedEntityGraphDefin
164167
metadataCollector.addNamedEntityGraph( namedEntityGraphDefinition );
165168
}
166169

170+
@Override
171+
public void addResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
172+
metadataCollector.addResultSetMapping( resultSetMappingDescriptor );
173+
}
174+
175+
@Override
176+
public void addFetchProfile(FetchProfile fetchProfile) {
177+
metadataCollector.addFetchProfile( fetchProfile );
178+
}
179+
180+
@Override
181+
public FetchProfile getFetchProfile(String name) {
182+
return metadataCollector.getFetchProfile( name );
183+
}
184+
185+
@Override
186+
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
187+
metadataCollector.addAuxiliaryDatabaseObject( auxiliaryDatabaseObject );
188+
}
189+
167190
@Override
168191
public void addAttributeConverter(Class<? extends AttributeConverter<?, ?>> converterClass) {
169192
metadataCollector.addAttributeConverter( converterClass );

src/main/java/org/hibernate/boot/models/bind/internal/InFlightMetadataCollectorAdapter.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
1010
import org.hibernate.boot.model.NamedEntityGraphDefinition;
1111
import org.hibernate.boot.model.convert.spi.RegisteredConversion;
12+
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
1213
import org.hibernate.boot.models.bind.spi.MetadataCollector;
14+
import org.hibernate.boot.query.NamedResultSetMappingDescriptor;
1315
import org.hibernate.boot.spi.InFlightMetadataCollector;
1416
import org.hibernate.engine.spi.FilterDefinition;
1517
import org.hibernate.mapping.Collection;
18+
import org.hibernate.mapping.FetchProfile;
1619
import org.hibernate.mapping.MappedSuperclass;
1720
import org.hibernate.mapping.PersistentClass;
1821
import org.hibernate.metamodel.CollectionClassification;
@@ -74,6 +77,26 @@ public void addNamedEntityGraph(NamedEntityGraphDefinition namedEntityGraphDefin
7477
metadataCollector.addNamedEntityGraph( namedEntityGraphDefinition );
7578
}
7679

80+
@Override
81+
public void addResultSetMapping(NamedResultSetMappingDescriptor resultSetMappingDescriptor) {
82+
metadataCollector.addResultSetMapping( resultSetMappingDescriptor );
83+
}
84+
85+
@Override
86+
public void addFetchProfile(FetchProfile fetchProfile) {
87+
metadataCollector.addFetchProfile( fetchProfile );
88+
}
89+
90+
@Override
91+
public FetchProfile getFetchProfile(String name) {
92+
return metadataCollector.getFetchProfile( name );
93+
}
94+
95+
@Override
96+
public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
97+
metadataCollector.addAuxiliaryDatabaseObject( auxiliaryDatabaseObject );
98+
}
99+
77100
@Override
78101
public void addAttributeConverter(Class<? extends AttributeConverter<?, ?>> converterClass) {
79102
metadataCollector.addAttributeConverter( converterClass );

0 commit comments

Comments
 (0)