Skip to content
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

HHH-13103 - Allow Hibernate Types to get access to the current configuration properties #2649

Closed
wants to merge 1 commit into from

Conversation

vladmihalcea
Copy link
Contributor

@vladmihalcea
Copy link
Contributor Author

@sebersole The reason why I think it's worth to implement this feature is that we are currently configuring the Java and SQL Type Descriptors in the constructor of the Type instances.

With this feature, we could allow the user to provide a specific constructor which takes the TypeBootstrapContext where we can pass the current SessionFactory properties or some other info we might need in future:

public ArrayType(TypeBootstrapContext typeBootstrapContext) {
    super( VarcharTypeDescriptor.INSTANCE, ArrayTypeDescriptor.INSTANCE );
    this.settings = typeBootstrapContext.getConfigurationSettings();
}

This way, we can get access to the current properties and the user can customize the custom Type object creation using the Hibernate properties.

One use case where I wanted this future is to customize the Jackson ObjectMapper used by the JSON Types. Currently, I can only do that via loading the hibernate.properties file externally, but not via the SessionFactory properties that might be passed by Spring or Spring Boot. This is the original issue that made me realize we could benefit from this new feature.

Let me know what you think.

@cberg-zalando
Copy link

@vladmihalcea I guess you will have to resolve the merge conflict before this moves any forward.

@vladmihalcea
Copy link
Contributor Author

@dreab8 I rebased this PR. From the upvotes this PR got, I think it's very useful and worth integrating.

Do you think it could be integrated in the next release? It's a small change and shouldn't be risky at all.

ConfigurationService configurationService = typeConfiguration.getServiceRegistry().getService(
ConfigurationService.class );
Map<String, Object> configurationSettings = configurationService.getSettings();
type = bootstrapContextAwareTypeConstructor.newInstance( new TypeBootstrapContext(
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of creating a new TypeBootstrapContext every time. I'd pass it the TypeConfiguration and be done with it, or have TypeConfiguration implement TypeBootstrapContext (after making it an interface - which it ought to be anyway imo)

Copy link
Member

Choose a reason for hiding this comment

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

Or better yet, have TypeFactory be the TypeBootstrapContext

Copy link
Member

Choose a reason for hiding this comment

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

I can work on this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

Copy link
Member

@sebersole sebersole left a comment

Choose a reason for hiding this comment

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

I've left a few comments..

@sebersole
Copy link
Member

Applied upstream with discussed change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants