Skip to content

HHH-16311 - Migrate away from UserType for enum handling #6246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

sebersole
Copy link
Member

Simple proof for handling enum values with the UserType machinery

@sebersole sebersole mentioned this pull request Mar 14, 2023
@gavinking
Copy link
Member

Does this eliminate all usages of org.hibernate.type.EnumType? (I ask because you didn't delete it.)

@sebersole
Copy link
Member Author

Well, that's the question isn't it ;) As I said, this is all just a quick proof. Still need to analyse all uses of EnumeratedValueResolution#getLegacyResolvedBasicType.

One use-case that comes to mind immediately is the SQM handling of enum value names as literals (i.e. ... gender=MALE).

@sebersole
Copy link
Member Author

Actually this was really easy to test. There were just a few errors - looking through them

@gavinking
Copy link
Member

One use-case that comes to mind immediately is the SQM handling of enum value names as literals (i.e. ... gender=MALE).

this is one of the things that was causing me a lot of pain when I tried to handle mapping to Postgres enum types.

@sebersole
Copy link
Member Author

As a quick test I changed EnumeratedValueResolution to always return the ConvertedBasicType, even for the #getLegacyResolvedBasicType case. That resulted in a few errors, but all were related to tests casting to the CustomType and EnumType classes directly. I'll push here in a bit to see what affects it has across all the databases.

@sebersole
Copy link
Member Author

This latest push should be pretty complete.

One change I'll probably revert is that this push limits "enum short name" handling to just implicit and explicit @Enumerated mappings. I was just playing around with hooks from EnumeratedValueResolution to think about native database type handling, aux database objects, etc.

@gavinking
Copy link
Member

OK then, I'll try making #6232 work on top of this patch, and see if it helps.

@sebersole
Copy link
Member Author

See especially InFlightMetadataCollector#registerEnumMapping...

I'm not yet sure what to think of the test failures from the last push. They stem from the fact that we now interpret mappings like @Enumerated(STRING) @Column(length=1) using Types.CHAR / Character. That change was never propagated into EnumType - meaning envers always saw Types.VARCHAR / String. I'm inclined to think the consistency is a good thing.

I have not yet looked into the Oracle test failure from the second push

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Mar 15, 2023

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@sebersole sebersole changed the title HHH-16125 - Migrate enum handling away from UserType HHH-16311 - Migrate away from UserType for enum handling Mar 15, 2023
@sebersole
Copy link
Member Author

The Oracle failure is ultimately https://hibernate.atlassian.net/browse/HHH-16333

Assuming all tests pass (other than the one failure on Oracle) in this latest push, I'm going to integrate this upstream

@sebersole
Copy link
Member Author

Integrated upstream

@sebersole sebersole closed this Mar 17, 2023
@sebersole sebersole deleted the enum-type branch March 17, 2023 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants