jdaugherty opened a new pull request, #16480:
URL: https://github.com/apache/grails-core/pull/16480
## Problem
On Hibernate 7, registering a user type with a `Class` value fails at
startup. The documented global mapping form is affected:
```groovy
grails.gorm.default.mapping = {
'user-type'(type: MyUserType, class: Boolean)
}
```
```
org.hibernate.MappingException: Could not resolve named type: class
com.example.MyUserType
```
`HibernateMappingBuilder.hibernateCustomUserType` stored
`args.type.toString()`. `Class.toString()` adds a `class ` prefix to the name,
so Hibernate tried to load a class called `class com.example.MyUserType`. The
`toString()` came in with da832c7ae6 (static compilation of the builder).
Hibernate 5 stores the value as given and never had this bug. The workaround is
to pass the class name as a string.
## Fix
Store `args.type` as given, as Hibernate 5 does. `Mapping.getTypeName`
already turns a `Class` into its name (`MappingSpec` covers both the `Class`
and string cases).
## Tests
- New `GlobalUserTypeMappingSpec`: starts a `HibernateDatastore` whose
`grails.gorm.default.mapping` registers a real `UserType` that stores `Boolean`
as `Y`/`N`. It runs once with the `Class` and once with the class name. Each
run checks that the property is bound to the user type, that the stored column
holds `Y`/`N`, and that values read back correctly. Before the fix, the `Class`
run fails with the error above.
- `HibernateMappingBuilderSpec`: a new case for a `Class` type, plus a
type-name check on the existing string case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]