You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "jdaugherty (via GitHub)" <gi...@apache.org> on 2026/10/02 13:59:18 UTC
[PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on code in PR #16480:
URL: https://github.com/apache/grails-core/pull/16480#discussion_r4174316840
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/UserTypeMappingSpec.groovy:
##########
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.orm.hibernate
+
+import java.sql.PreparedStatement
+import java.sql.ResultSet
+import java.sql.SQLException
+import java.sql.Types
+
+import groovy.transform.CompileStatic
+
+import grails.gorm.annotation.Entity
+import grails.gorm.hibernate.HibernateEntity
+import org.grails.datastore.mapping.core.DatastoreUtils
+import org.grails.orm.hibernate.cfg.Settings
+import org.hibernate.mapping.SimpleValue
+import org.hibernate.type.descriptor.WrapperOptions
+import org.hibernate.usertype.UserType
+import spock.lang.Specification
+import spock.lang.Unroll
+
+class UserTypeMappingSpec extends Specification {
+
+ @Unroll
+ void "a user-type in the default mapping given as #description applies to every entity"() {
Review Comment:
The default-mapping test says the user type applies to every entity, but only `UserTypeFlag` is registered. The class-local case (line 81) and the precedence case (line 97) also distinguish scope mainly through `typeNameOf`, which reads Hibernate metadata. A Boolean round-trip alone would still pass if the custom type were not bound.
Non-blocking follow-up: register and persist two entities in the default case, persist the unaffected entity in the class-local case, and assert standard physical Boolean storage for the unaffected and overridden properties. The Class-versus-string regression itself is already covered by the save/read and the `Y`/`N` column checks.
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on code in PR #16480:
URL: https://github.com/apache/grails-core/pull/16480#discussion_r4174469926
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/UserTypeMappingSpec.groovy:
##########
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.orm.hibernate
+
+import java.sql.PreparedStatement
+import java.sql.ResultSet
+import java.sql.SQLException
+import java.sql.Types
+
+import groovy.transform.CompileStatic
+
+import grails.gorm.annotation.Entity
+import grails.gorm.hibernate.HibernateEntity
+import org.grails.datastore.mapping.core.DatastoreUtils
+import org.grails.orm.hibernate.cfg.Settings
+import org.hibernate.mapping.SimpleValue
+import org.hibernate.type.descriptor.WrapperOptions
+import org.hibernate.usertype.UserType
+import spock.lang.Specification
+import spock.lang.Unroll
+
+class UserTypeMappingSpec extends Specification {
+
+ @Unroll
+ void "a user-type in the default mapping given as #description applies to every entity"() {
Review Comment:
Done in 5287b3a002. The default-mapping case now registers, saves and checks two entities. The class-local case also saves the unaffected entity, and it and the precedence case now assert that the column holds `TRUE`/`FALSE`, not `Y`/`N`.
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16480:
URL: https://github.com/apache/grails-core/pull/16480#issuecomment-5956201712
## ✅ All tests passed ✅
🏷️ Commit: e2d23b1f0b994c6e0fc2abeb7b54ccc6dea05013
▶️ Tests: 90342 executed
⚪️ Checks: 91/91 completed
---
_Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #16480:
URL: https://github.com/apache/grails-core/pull/16480#issuecomment-5972158866
<!-- Bito Reply -->
The observation regarding the test coverage is accurate. Currently, the test only registers `UserTypeFlag` in the default mapping case, which does not fully verify that the mapping applies to every entity as intended. Additionally, the reliance on `typeNameOf` for scope distinction is correct, but as noted, a Boolean round-trip could potentially pass even if the custom type were not correctly bound.
To improve the test coverage, it is recommended to:
1. Register and persist two distinct entities in the default mapping case to verify the global application of the user type.
2. Persist an unaffected entity in the class-local case to ensure the scope is correctly isolated.
3. Assert standard physical Boolean storage for both the unaffected and overridden properties to confirm the custom type is correctly bound and utilized.
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #16480:
URL: https://github.com/apache/grails-core/pull/16480#issuecomment-5955237776
## [Codecov](https://app.codecov.io/gh/apache/grails-core/pull/16480?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 59.0417%. Comparing base ([`9a2291b`](https://app.codecov.io/gh/apache/grails-core/commit/9a2291bfcfec9a9fbe44d7a831033bd3086dad0f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`e2d23b1`](https://app.codecov.io/gh/apache/grails-core/commit/e2d23b1f0b994c6e0fc2abeb7b54ccc6dea05013?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 8 commits behind head on 8.0.x.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/grails-core/pull/16480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## 8.0.x #16480 +/- ##
==================================================
+ Coverage 59.0398% 59.0417% +0.0018%
- Complexity 24551 24552 +1
==================================================
Files 2175 2175
Lines 107668 107668
Branches 19618 19618
==================================================
+ Hits 63567 63569 +2
+ Misses 35220 35219 -1
+ Partials 8881 8880 -1
```
[see 1 file with indirect coverage changes](https://app.codecov.io/gh/apache/grails-core/pull/16480/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #16480:
URL: https://github.com/apache/grails-core/pull/16480#issuecomment-5972564341
## 🔎 No tests executed 🔎
🏷️ Commit: 5287b3a00250a878790a80557686eb52b5ccd894
▶️ Tests: 0 executed
⚪️ Checks: 2/2 completed
---
_Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Hibernate 7: accept a Class as the type of a 'user-type' mapping [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty merged PR #16480:
URL: https://github.com/apache/grails-core/pull/16480
--
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: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org