Similarly, CDI suffers from the same problem.
CDI beans are not defined as Jakarta EE Components in the Platform specification, at least not like servlets and EJBs.
That is, CDI bean do not have a defined “java:comp” JNDI context.
Instead, CDI bean just happen to always run in the context of either a servlet or EJB, so either the Web Container or EJB Container will have established a “java:comp” that CDI can access.
I don't think CDI "suffers" from the problem. I'd rather say CDI avoids this problem altogether. CDI is initialized from the web container. The web container sets java:comp per web application (or, for the one and only application in various EE runtimes). And that's it.
Every CDI bean has access to the one and only java:comp namespace in the application it's a part of, exactly because of what you say; it simply runs in the context of the web container.
Since we are discussing the integration of CDI and Jakarta Persistence, it seems rather odd to rely on “java:comp”, which isn’t defined for either.
I’m not saying it wouldn’t work, but if we were to go with this approach, then the two specifications (and perhaps the Platform specification) should be updated to indicate that the “Container” needs to make some “java:comp” JNDI context available to
CDI and Persistence during application start, and what needs to be available in that context.
We do indeed need a better specification of ordering and how everything in Jakarta EE starts up, including the web container, CDI, Jakarta Persistence and various other things. But I don't think CDI or Jakarta Persistence have to be updated specifically here.
Maybe look at Jakarta Faces as a reference. How is Jakarta Faces able to use "java:comp/ValidatorFactory" without Jakarta Faces or CDI needing to indicate anything to the Container to make “java:comp” available?
Kind regards,
Arjan Tijms