-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-16069 - Defer handling of custom types until after deployment time #5994
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
Conversation
3f0f9fc
to
3aacc4e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. A few comments below.
I'm mainly concerned about changing the behavior of getBean
in BeanContainer
, since Hibernate Search relies on that.
* @implNote Defaulted for backwards compatibility | ||
*/ | ||
<T> ManagedBean<T> getBean(String beanName, Class<T> beanContract); | ||
default <T> ManagedBean<T> getBean(Class<T> beanClass, boolean cdiRequiredIfAvailable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to use an enum instead of a boolean, both for more explicit code on call sites and to be free to add other behavior later if need be?
if ( usableBeanManager == null ) { | ||
BeanInstanceProducer fallbackProducer, | ||
boolean cdiRequiredIfAvailable) { | ||
if ( !cdiRequiredIfAvailable ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the cdiRequiredIfAvailable
flag be ignored if usableBeanManager
is non-null (and thus CDI is already available)?
E.g.:
if ( !cdiRequiredIfAvailable ) { | |
if ( !cdiRequiredIfAvailable && usableBeanManager == null ) { |
That way if the caller is lucky and CDI was already initialized, they can get a CDI bean.
Class<B> beanType, | ||
LifecycleOptions lifecycleOptions, | ||
BeanInstanceProducer fallbackProducer) { | ||
return getBean( beanType, lifecycleOptions, fallbackProducer, false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the default behavior, though... Including for Hibernate Search in the "delayed" case. I'm not sure of the implications.
Since you're (likely) always going to call getBean()
with the explicit cdiRequiredIfAvailable
flag yourself, can you please preserve the legacy behavior for this method? Just for backwards compatibility of integrations?
Class<B> beanType, | ||
LifecycleOptions lifecycleOptions, | ||
BeanInstanceProducer fallbackProducer, | ||
boolean cdiRequiredIfAvailable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe another name would be better, since BeanContainer
can be used for non-CDI implementations? E.g. beanContainerRequiredIfAvailable
or something like that.
fallbackBeanInstanceProducer, | ||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can say for sure that existing integrators using this API (i.e. Hibernate Search) do not, at the moment, use true
.
Since these tests are specifically about checking compatibility with Hibernate Search, it's probably better to keep calling the old method without the cdiRequiredIfAvailable
flag?
This form circumvents CDI hosting of UserType impls when extended or delayed strategies are used.
Alternative to #5992