Repository navigation
fix(hibernate7): apply maxSize and type text to Map, List and Set element columns - #16922
borinquenkid wants to merge 5 commits into
Conversation
…ment columns A mapped type: 'text' on a basic collection failed with "Unable to load class [text]" because the type name was handed to Hibernate as a user collection type. Basic collections no longer pass it as the collection type, and the element column now honors maxSize, inList and type text. Fixes #16897 Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Not approving. A collection inList whose allowed values are collections prevents startup. The new tests are inside an enum, so they never run.
| if (elementConfig != null) { | ||
| Column elementColumn = simpleValueColumnFetcher.getColumnForSimpleValue(element); | ||
| if (elementColumn != null) { | ||
| stringColumnConstraintsBinder.bindStringColumnConstraints(elementColumn, elementConfig, typeName); |
There was a problem hiding this comment.
tags inList: [['a'], ['b']] on a List of String throws while the mapping is built. The allowed value is the whole list, not a string. Do not read those allowed values as element strings.
| } | ||
|
|
||
| enum BCEBStatus { ACTIVE, INACTIVE } | ||
| enum BCEBStatus { ACTIVE, INACTIVE |
There was a problem hiding this comment.
The new maxSize, text, and default-length cases sit inside BCEBStatus, after the specification has closed. Running the specification never runs them. Move them into the specification.
…pe, not the length from maxSize or inList The maxSize of a collection bounds the number of its elements, and its inList lists whole collections, so neither is the length of an element. A List of String with maxSize 2 was valid with one element of six characters, and saving it failed on a varchar(2); an inList of lists, such as [['a'], ['b']], was read as element strings and stopped the mapping from being built. The column of the elements of a list, a set or a map is left unbounded for type text and keeps its length otherwise; the documentation says to use type text for long values. The specs that had been written inside the BCEBStatus enum, where they never ran, are in the specification. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley Both are addressed in the new commit, and it changes more than your two points, for the reason in your review of the Hibernate 5 counterpart (#16923).
A length for the element column is not something The Hibernate 7 module (4,632 tests) and Branch policy: this commit adds no public type and no throw. Where the PR belongs is still open; I have not moved it. If you find another shape that does not reproduce first time, a failing spec on a throwaway branch, or the few lines you ran, would help me a lot. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A registered collection type is ignored for a basic collection.
| * values or components the mapped {@code type} names the type of the elements, so it is not a collection type. | ||
| */ | ||
| public String getTypeName(HibernateToManyProperty property) { | ||
| if (property instanceof HibernateToManyCollectionProperty) { |
There was a problem hiding this comment.
A map, set, or list registers its own collection type. The mapping uses the default collection instead, because this returns before that registration is read. Use the registered type.
…s used, and a mapped element type is not one Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Pushed 48e084a. You are right: my change returned no type name for every collection of basic values, which also dropped a collection type the mapping registers. The test: I did not add a row that runs a real |
jdaugherty
left a comment
There was a problem hiding this comment.
The collection maxSize/inList handling and the tests previously placed inside the enum are corrected. The latest guard preserves a collection type supplied directly on a property, but the registered-type concern remains for an actual user-type registration.
P2 — Inspect the effective registered collection type before returning null. CollectionType.java:73–82 asks getUserType(), which reads only the property's own mapped type. A basic map can instead register a concrete Hibernate UserCollectionType this way:
Map<String, String> attributes
static mapping = {
'user-type'(class: Map, type: CustomMapType)
}Here getUserType() returns null, although the normal type-name resolution consults the owning mapping and obtains CustomMapType. The new guard returns before that resolution and substitutes the default collection implementation. Registrations through grails.gorm.default.mapping have the same problem. The two resolution paths are visible in HibernatePersistentProperty.java:116–133.
Please preserve the effective registration, including its owner/default-mapping fallback. The new registered-type rows mock getUserType() to return a class, bypassing the failing lookup. Add a datastore-level test with a real collection implementation registered through the DSL, and verify that it remains the collection type while text still applies only to elements. This review is source-based; I have not rerun tests.
… basic collection stays its collection type The guard asked the property for the type of its own mapping only, so a user collection type registered with a user-type mapping of the owner, or of grails.gorm.default.mapping, for the class of the property was dropped for the default collection implementation. The guard now looks at the type name that the property resolves, own mapping first and then the registration, and a name that is not a user collection type, such as text, is still a type of the elements. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Fixed in e961db9: the guard looks at the type name that the property resolves, its own mapping first and then the registration of its owner, or of
|
Fixes #16897
Problem
type: 'text'on a basic collection (Map, List or Set of simple values) failed metadata build withUnable to load class [text], because the type name was passed to Hibernate as a user collection type class.Change
CollectionType.getTypeNamereturns null for basic collection properties, so the mapped type is no longer treated as a collection type class.MapSecondPassBinderandBasicCollectionElementBinderleave the element column unbounded fortype: 'text'(StringColumnConstraintsBinder.bindTextType).maxSizeandinListdo not size the element column. For a collection,maxSizeis the number of its elements andinListlists whole collections, so aListofStringwithmaxSize: 2is valid with one element of any length.type.adocdocuments the behavior with aCmsPageexample and says to usetype: 'text'for long values.Tests
MapElementColumnSpeccovers default, text and maxSize on Map and List, aninListof lists, a list withinmaxSizethat is saved, the join column name, and the unchanged key column.MapSecondPassBinderSpec,BasicCollectionElementBinderSpec,StringColumnConstraintsBinderSpecandMapCollectionTypeSpec.Not covered
sqlTypeis not expressible in the mapping DSL, so it is out of scope.maxSizecannot give it, and no mapping setting does yet; see A joinTable column given as a map becomes the column name, and there is no way to set the length of a collection element column #17025.https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
Branch policy: the schema binders are touched by this pull request's own change (the element column of a basic collection, with its upgrade note); the latest commit only keeps a registered user collection type, as 8.0.x does