Skip to content

fix(hibernate5): honour length on the id in MappingBuilder.orm - #16987

Open
borinquenkid wants to merge 4 commits into
7.2.xfrom
fix/mapping-builder-id-length-7.0.x
Open

borinquenkid wants to merge 4 commits into
7.2.xfrom
fix/mapping-builder-id-length-7.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Mapping.id(Map) bound the map to Identity, which has no length, so id generator: 'assigned', length: 20 inside MappingBuilder.orm was dropped and the id column stayed VARCHAR(255). The length now goes to the id column, the way the plain mapping closure already did.

Verified locally: the new IdentityLengthSpec reads the column length from the schema; the MappingBuilder.orm feature fails (255) without the change and passes with it, and the mapping closure feature passes before and after. CodeNarc is clean. Hibernate 7 has the same gap in HibernateSimpleIdentity on 8.0.x, which a separate PR will cover.

Fixes #14497

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

Mapping.id(Map) bound the map to Identity, which has no length, so the
value was dropped and the id column stayed VARCHAR(255). The length now
goes to the id column the way the mapping closure form already did.

Fixes #14497

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approving. A length on the id is copied. A wildcard default, such as a SQL type for every column, is dropped for that id.

Answers the review of #16987: the id config started blank, which stopped the fallback to the '*' defaults, so an id with a length lost the wildcard SQL type. It now starts from the wildcard defaults, as every other property does, and the length is set on that column.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid

Copy link
Copy Markdown
Member Author

Answers the wildcard point (Mapping.groovy, bindIdentityColumnLength). The id's config now starts from the '*' defaults, as every other property's does, and the length is set on that column, so an id with a length keeps the SQL type the wildcard gives.

IdentityLengthSpec has the wildcard rows for MappingBuilder.orm and for the mapping closure; the MappingBuilder.orm row fails without the change (1 of 4 rows). Hibernate 5 core: 691 tests, 0 failures; codeStyle clean.

Not tried: a wildcard that sets a column name, which would also have to reach the id.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. A later column declaration for the id no longer merges into the column this length created, so the identifier has two columns.

…s length made

id generator: 'assigned', length: 20 followed by property('id') { column { name 'custom_id' } } gave the id two columns, and
mapping validation failed. The length sizes the id column the mapping builder keeps for it, and marked that column as taken, so
the column a later declaration makes was added beside it. The column a length creates, or takes over from the wildcard defaults,
is now left open to the next declaration, as a copy of the defaults is, so the identifier keeps one column, in either order.

IdentityLengthSpec gains rows for the length before and after the declaration, with a wildcard SQL type, and for a declaration
that gives no name.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid

Copy link
Copy Markdown
Member Author

Thank you, that was a real gap. The length sizes the id column the mapping builder keeps for the identifier, and it marked that column as taken, so the column a later declaration makes (property('id') { column { name 'custom_id' } }) was added beside it: two columns, and mapping validation failed.

The column that a length creates, or takes over from the wildcard defaults, is now left open to the next declaration, as a copy of the defaults is, so the identifier keeps one column. I checked both orders, because the same gap could have shown the other way round: with the length after the declaration, the id also keeps one column, the length being set on the column the declaration made.

IdentityLengthSpec has four new rows, all through MappingBuilder.orm and checked against the table's columns: the length before the declaration, the length after it, the length before it with a wildcard sqlType 'char(30)' (one column named custom_id, sized 30, because the wildcard type decides the size, as in the existing wildcard rows), and a later declaration that gives no name (one id column, type unchanged). They fail without the fix, the Hibernate 5 module is green (695 tests), and codeStyle is clean.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items this review found have been addressed. A later declaration of the id fills in the column its length made, and the length stays.

@borinquenkid
borinquenkid marked this pull request as draft November 26, 2026 00:58
@borinquenkid borinquenkid added no ci and removed run ci labels Nov 26, 2026
The 7.0.x patch line takes no more fixes after the 2026-11-25 releases;
this PR moves to 7.2.x.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid
borinquenkid changed the base branch from 7.0.x to 7.2.x November 26, 2026 02:42
@borinquenkid

Copy link
Copy Markdown
Member Author

Moved to 7.2.x: after the 2026-11-25 releases the 7.x line takes fixes on 7.2.x only. The branch has 7.2.x merged in and its module tests and codeStyle pass on it. Nothing else changed, so the review so far still applies; a fresh approval on the new head is needed for the merge rule.

@borinquenkid
borinquenkid marked this pull request as ready for review November 26, 2026 02:42
@borinquenkid borinquenkid added run ci and removed no ci labels Nov 26, 2026
@testlens-app

testlens-app Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

Tip

Inspect all details with the TestLens CLI: testlens pr 16987

CI / Functional Tests (Java 17, indy=false) > :grails-test-examples-datasources:integrationTest

Test Runs Flakiness
OsivRequestSessionSpec > a task a request returns lazily loads associations of the entities its action loaded ❌ ✅ 🚫 0% 🟢

CI / Functional Tests (Java 21, indy=false) > :grails-test-examples-datasources:integrationTest

Test Runs Flakiness
OsivRequestSessionSpec > a task a request returns lazily loads associations of the entities its action loaded ❌ ❌ ✅ 0% 🟢

🏷️ Commit: 2e9aa68
▶️ Tests: 12053 executed
⚪️ Checks: 155/155 completed

Test Failures

OsivRequestSessionSpec > a task a request returns lazily loads associations of the entities its action loaded (:grails-test-examples-datasources:integrationTest in CI / Functional Tests (Java 17, indy=false) | Attempt 1/3)
Condition failed with Exception:

http('/requestSession/lazyVolumes?name=asynchronous').assertEquals(200, 'first,second')
|                                                     |
|                                                     org.opentest4j.AssertionFailedError: HTTP Status differs
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.verify(TestHttpResponse.groovy:980)
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.verifyStatus(TestHttpResponse.groovy:840)
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.assertEquals(TestHttpResponse.groovy:580)
|                                                     	at functionaltests.OsivRequestSessionSpec.a task a request returns lazily loads associations of the entities its action loaded(OsivRequestSessionSpec.groovy:109)
<org.apache.grails.testing.http.client.TestHttpResponse@13b0a2ef delegate=(GET http://localhost:35761/requestSession/lazyVolumes?name=asynchronous) 500 jsonSlurperConfig=org.apache.grails.testing.http.client.utils.JsonUtils$SlurperConfig(null, null, null, null, null) xmlSlurperConfig=org.apache.grails.testing.http.client.utils.XmlUtils$SlurperConfig@7dcadb11>

	at functionaltests.OsivRequestSessionSpec.a task a request returns lazily loads associations of the entities its action loaded(OsivRequestSessionSpec.groovy:109)
Caused by: org.opentest4j.AssertionFailedError: HTTP Status differs
	at org.apache.grails.testing.http.client.TestHttpResponse.verify(TestHttpResponse.groovy:980)
	at org.apache.grails.testing.http.client.TestHttpResponse.verifyStatus(TestHttpResponse.groovy:840)
	at org.apache.grails.testing.http.client.TestHttpResponse.assertEquals(TestHttpResponse.groovy:580)
	... 1 more
OsivRequestSessionSpec > a task a request returns lazily loads associations of the entities its action loaded (:grails-test-examples-datasources:integrationTest in CI / Functional Tests (Java 21, indy=false) | Attempt 2/3)
Condition failed with Exception:

http('/requestSession/lazyVolumes?name=asynchronous').assertEquals(200, 'first,second')
|                                                     |
|                                                     org.opentest4j.AssertionFailedError: HTTP Status differs
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.verify(TestHttpResponse.groovy:980)
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.verifyStatus(TestHttpResponse.groovy:840)
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.assertEquals(TestHttpResponse.groovy:580)
|                                                     	at functionaltests.OsivRequestSessionSpec.a task a request returns lazily loads associations of the entities its action loaded(OsivRequestSessionSpec.groovy:109)
<org.apache.grails.testing.http.client.TestHttpResponse@42306a87 delegate=(GET http://localhost:42033/requestSession/lazyVolumes?name=asynchronous) 500 jsonSlurperConfig=org.apache.grails.testing.http.client.utils.JsonUtils$SlurperConfig(null, null, null, null, null) xmlSlurperConfig=org.apache.grails.testing.http.client.utils.XmlUtils$SlurperConfig@3344bc4>

	at functionaltests.OsivRequestSessionSpec.a task a request returns lazily loads associations of the entities its action loaded(OsivRequestSessionSpec.groovy:109)
Caused by: org.opentest4j.AssertionFailedError: HTTP Status differs
	at org.apache.grails.testing.http.client.TestHttpResponse.verify(TestHttpResponse.groovy:980)
	at org.apache.grails.testing.http.client.TestHttpResponse.verifyStatus(TestHttpResponse.groovy:840)
	at org.apache.grails.testing.http.client.TestHttpResponse.assertEquals(TestHttpResponse.groovy:580)
	... 1 more
OsivRequestSessionSpec > a task a request returns lazily loads associations of the entities its action loaded (:grails-test-examples-datasources:integrationTest in CI / Functional Tests (Java 21, indy=false) | Attempt 1/3)
Condition failed with Exception:

http('/requestSession/lazyVolumes?name=asynchronous').assertEquals(200, 'first,second')
|                                                     |
|                                                     org.opentest4j.AssertionFailedError: HTTP Status differs
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.verify(TestHttpResponse.groovy:980)
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.verifyStatus(TestHttpResponse.groovy:840)
|                                                     	at org.apache.grails.testing.http.client.TestHttpResponse.assertEquals(TestHttpResponse.groovy:580)
|                                                     	at functionaltests.OsivRequestSessionSpec.a task a request returns lazily loads associations of the entities its action loaded(OsivRequestSessionSpec.groovy:109)
<org.apache.grails.testing.http.client.TestHttpResponse@41acbb51 delegate=(GET http://localhost:37657/requestSession/lazyVolumes?name=asynchronous) 500 jsonSlurperConfig=org.apache.grails.testing.http.client.utils.JsonUtils$SlurperConfig(null, null, null, null, null) xmlSlurperConfig=org.apache.grails.testing.http.client.utils.XmlUtils$SlurperConfig@104f10a7>

	at functionaltests.OsivRequestSessionSpec.a task a request returns lazily loads associations of the entities its action loaded(OsivRequestSessionSpec.groovy:109)
Caused by: org.opentest4j.AssertionFailedError: HTTP Status differs
	at org.apache.grails.testing.http.client.TestHttpResponse.verify(TestHttpResponse.groovy:980)
	at org.apache.grails.testing.http.client.TestHttpResponse.verifyStatus(TestHttpResponse.groovy:840)
	at org.apache.grails.testing.http.client.TestHttpResponse.assertEquals(TestHttpResponse.groovy:580)
	... 1 more

Learn more about TestLens at testlens.app/docs.

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI assisted review

The length now reaches the id column, and later id declarations fill in that same column. CI skipped the tests here; a run ci label would confirm IdentityLengthSpec. LGTM.

@borinquenkid
borinquenkid marked this pull request as draft November 26, 2026 07:33
@borinquenkid
borinquenkid marked this pull request as ready for review November 26, 2026 07:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants