Using custom ByteCodeProvider in Hibernate 6?


I am having similar issues like this one here [HHH-13242] - Hibernate JIRA that is marked as fixed but not sure why. We had custom ByteCodeProvider with hibernate5 but when we moved to hibernate6 then our provider is just being ignored. Seems like this code in EntityRepresentationStrategyPojoStandard class

final BytecodeProvider bytecodeProvider = Environment.getBytecodeProvider();

is not allowing to use custom byte provider. When this is changed to

final BytecodeProvider bytecodeProvider = creationContext.getBootstrapContext().getServiceRegistry().getService(BytecodeProvider.class);

then our custom bytecode provider is used and works as expected.
What is proper way to configure custom ByteCodeProvider in Hibernate6?


Thanks for spotting the inconsistency on [HHH-13242] - Hibernate JIRA, addressed that.

It’s the first time I hear of anyone actually being brave enough to maintain a custom BytecodeProvider; indeed I don’t think it’s currently configurable - I have it on my wishlist for things to improve sometime soon to remove the global environment settings; that’s why these methods are marked as deprecated. Haven’t had a chance to work on it but I appreciate the existence of such system properties require some clarifications.

I’ll try to find some time to remove the misleading properties; we can then also take in consideration to allow integrating a custom one.

Could you give me an idea of why you need a custom implementation?

Ideally I’d want to evolve this in small steps:

  1. Remove the static & global aspects, allowing only a regular configuration property to set either “bytebuddy” or “none”. Allow overrides to happen via a ServiceInitiator.
  2. Move the ByteBuddy enhancer into a separate jar, making it optional.
  3. (Optionally, pending your feedback) Allow to drop in a different implementation instead of the ByteBuddy based implementation.

It was used to add compile time proxy and to disable enhancer, but seems like we have to give it up in hibernate6.

You might not have to give up on it: we might re-introduce the capability if there’s good reasons but if we can have your need covered in a simpler way that might be preferrable.

What do you mean by “compile time proxy”? Are these different from the build time enhancers we already provide?