-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
ManagedBeanRegistry CDI lifecycle fixes #2092
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
ManagedBeanRegistry CDI lifecycle fixes #2092
Conversation
1d4fb72
to
f0f1c8f
Compare
@sebersole Following @Sanne's advice, I managed to avoid the switch to WildFly 12. This PR now targets WildFly 11, with only a patch file applied to the server to upgrade Weld to a version supporting CDI 2.0. |
f0f1c8f
to
3d24c1c
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.
Overall these seem like some very complicated changes. I'm going to have to sit down and look through them
* even if there is already an instance in the CDI context. | ||
* This means singletons are not really singletons, but this seems to be the behavior required by | ||
* the JPA 2.2 spec. | ||
*/ |
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.
But see, this is not true. For a given class we only ever generate one ManagedBean instance = they are singletons (unless of course they are used again in a non-JPA context). Notice the caching of them initially in a Map keyed by class...
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.
unless of course they are used again in a non-JPA context
My point exactly. They are singleton in the JPA context only, not in the CDI context overall. I can rephrase the comment to clarify that if you like.
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.
Also, even in the JPA context, such "not-actually-singleton" beans will be instantiated once per ServiceRegistry
, which unless I'm mistaken means once per SessionFactory
/persistence unit. So even from the JPA point of view, they cannot always be viewed as singletons.
ede1255
to
65bc115
Compare
Now working on tests as discussed; I couldn't finish today, but I'll probably be able to push something on Monday. |
cf51133
to
3b600f5
Compare
Added non-regression tests as requested. |
3b600f5
to
a4dfcc8
Compare
@yrodiere Just because it is easier to ask than to see it in the PR.... you are using CDI 2.0's SE bootstrap now, right? Instead of using WildFly? |
@sebersole Yes. I did exactly what you did in your own tests. |
I do still see CDI 2.0 patches against WildFly though :
https://github.com/hibernate/hibernate-orm/pull/2092/files#diff-1d01abe59e76ef186ae0415fefca546d
Is that just for completeness? If we are not testing "CDI in WildFly" (and
we should not be), then this should not be needed.
…On Fri, Jan 12, 2018 at 7:30 AM Yoann Rodière ***@***.***> wrote:
@sebersole <https://github.com/sebersole> Yes. I did exactly what you did
in your own tests.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2092 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOUE-8Y6plQY-6tn1OX8z-ldZRaypa4ks5tJ15YgaJpZM4RIVGj>
.
|
It is. If anything relies on CDI in your WildFly ITs, without this patch the IT will probably fail. If you don't think you'll ever use CDI in your WildFly ITs, then yes you can skip this commit. I can remove it if you want. |
We currently do not do any in-WF CDI tests (we used to, but I changed that
to use the SE bootstrapping). IMO that's outside the scope of what we
should be testing.
I can just remove that as I integrate your PR locally. Or you can if you
really want to :)
…On Fri, Jan 12, 2018 at 7:44 AM Yoann Rodière ***@***.***> wrote:
Is that just for completeness?
It is. If anything relies on CDI in your WildFly ITs, without this patch
the IT will probably fail.
If you don't think you'll ever use CDI in your WildFly ITs, then yes you
can skip this commit. I can remove it if you want.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2092 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOUE27zvD_Zsyj_8ceCPLh2-nhyKQ0Vks5tJ2GlgaJpZM4RIVGj>
.
|
This commit should not change the current behavior, it is only about moving code to separate classes to make the following changes clearer.
…epending on the 'shouldRegistryManageLifecycle' parameter The registry should not manage the bean lifecycle when 'shouldRegistryManageLifecycle' is false. The easiest way to do so is to use BeanManager.createInstance to retrieve beans in the Standard CDI lifecycle strategy: it correctly retrieves singletons from the CDI context instead of instantiating them again. Also, fix javax.enterprise.inject.spi.Bean-based instance destructions: we used to only request destruction to the creational context, which is wrong because it may skip the execution of @PostDestroy methods in particular.
…n when possible This should take care of @Alternative in particular.
…ryManageLifecycle = false
a4dfcc8
to
3f67a2d
Compare
I rebased on master and removed the commit. |
Ok, thanks. I am integrating this now.
…On Fri, Jan 12, 2018 at 8:47 AM Yoann Rodière ***@***.***> wrote:
I can just remove that as I integrate your PR locally. Or you can if you
really want to :)
I rebased on master and removed the commit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2092 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOUE3XCf6Xo92ri27J2CRQQypHhvXXKks5tJ3BzgaJpZM4RIVGj>
.
|
@yrodiere I did some work on top of this as discussed and pushed upstream in prep for tomorrow's Beta1 release. It's just a Beta, so if you find anything we need to change its not a big deal - we'll get it into the next one |
@sebersole Here are the fixes I mentioned yesterday regarding the
ManagedBeanRegistry
. Mainly this is about making sure that, whenshouldRegistryManageLifecycle
isfalse
, the registry really doesn't manage the CDI lifecycle at all and delegates to the CDI runtime.All of the commits in this PR are follow-ups to already-fixed tickets:
WARNING: I had to use CDI 2.0 APIs, and those APIs are not available in WildFly 11. So I added a build step to patch the WildFly server.