Skip to content

HHH-16125 PostgreSQL enum types + reimplementation of enum support #6448

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 11 commits into from

Conversation

gavinking
Copy link
Member

First try was #6232.

This time things went somewhat more smoothly, except that I ran into a problem with enum types in foreign keys.

I'm now concerned that we'll have to abandon the whole specialiedTypeDeclaration thing I added to let converters have a vote on the generated DDL types. In place of that I would probably introduce SqlTypes.ENUM and pass the enum type along with the Size class. So there would be a real DdlType for native enums.

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Apr 24, 2023

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+
    ↳ Offending commits: [750a9ad, df9f70e]

› This message was automatically generated.

@@ -36,32 +36,46 @@
*/
int getSqlTypeCode();

default String getTypeName(Size columnSize, Class<?> returnedClass) {
return getTypeName( columnSize );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [DdlType.getTypeName](1) should be avoided because it has been deprecated.
@gavinking gavinking changed the title HHH-16125 second failed POC for PostgreSQL enum types HHH-16125 PostgreSQL enum types + reimplementation of enum support Apr 27, 2023

try ( SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory() ) {
EntityPersister p = sf.getRuntimeMetamodels()
.getMappingMetamodel()
.getEntityDescriptor( AddressLevel.class.getName() );
//noinspection unchecked
ConvertedBasicType<Nature> runtimeType = (ConvertedBasicType<Nature>) p.getPropertyType( "nature" );
assertEquals( Types.VARCHAR, runtimeType.getJdbcType().getJdbcTypeCode() );
BasicType<Nature> runtimeType = (BasicType<Nature>) p.getPropertyType( "nature" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [EntityPersister.getPropertyType](1) should be avoided because it has been deprecated.
throw new HibernateException("Enum class not found: " + enumClassName, exception);
}
} else {
enumClass = (Class<T>) reader.getReturnedClass().asSubclass(Enum.class);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [reader](1) may be null at this access as suggested by [this](2) null guard.
@gavinking gavinking force-pushed the 16125 branch 2 times, most recently from 00ef478 to b0f447e Compare April 28, 2023 09:32
@gavinking gavinking marked this pull request as draft April 28, 2023 11:00
@@ -167,8 +165,7 @@

@Incubating
default String getSpecializedTypeDeclaration(Dialect dialect) {
final BasicValueConverter<T, ?> valueConverter = getValueConverter();
return valueConverter == null ? null : valueConverter.getSpecializedTypeDeclaration( getJdbcType(), dialect );
return getMappedJavaType().getSpecializedTypeDeclaration( getJdbcType(), getValueConverter(), dialect );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [JavaType.getSpecializedTypeDeclaration](1) should be avoided because it has been deprecated.
@gavinking gavinking force-pushed the 16125 branch 6 times, most recently from 305850d to 0c6d089 Compare April 29, 2023 06:46
incl attempt to fix PK to FK copying
this is probably a pre-existing hole in the logic,
not related really related to my work
- introduce SqlTypes.ENUM
- no more converters!
- finish of Potgres enum support
- disable BIND for enums in Criteria on PostgreSQL
  (PostgreSQL doesn't do the needed type conversion to the enum type)
fixes allowing correct serialization/deserialization of enums
includes workaround for StructJdbcType sending us a BigDecimal (need better solution)
…ion details

these are bad tests; they don't test observable behavior
@gavinking
Copy link
Member Author

Superseded by #6480.

@gavinking gavinking closed this Apr 29, 2023
@gavinking gavinking deleted the 16125 branch June 15, 2023 10:57
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.

1 participant