I became aware of this discussion through the topic "EJB ->
CDI migration" and would like to briefly share my thoughts about
it.
My fear here is to "ban" EJBs as something outdated, complicated
and unnecessary. But is that right?
I myself run with imixs.org a
very large Jakarta EE project. And my opinion is that you should
always implement the DataAccessLayer as also complex
ProcessingServices in a stateless EJB in order to make use of the
transaction capability.
I do know that you can also use CDI for data access. But is it the
same?
For example in my own project (a BPMN workflow engine) the
DataAccess Service as also the Engine itself is implemented as a
stateless EJB.
A project that is using the library just need to inject the
WorkflowEngine. The user does not have to think about transactions
or EJBs at this moment. The app developer can now extend the
engine behavior by implementing so called 'Plug-Ins' as simple CDI
beans. Such a CDI bean is a kind of adapter class that can for
example react on specific CDI Events in the processing life-cycle.
And of course the developer can again inject the DataService form
the Workflow Engine to create new data.
The point is that if something goes totally wrong, the default
transaction manager takes care about the rollback over all
layers.
And this all comes for free just because of using the stateless
local EJB pattern. For the developer there is no need to think
about EJBs at all.
I may be wrong here, but I would always advise a developer to
implement the data access layer via EJBs to keep the rest of the
application as lean as possible.
Therefore, in my opinion, EJBs play an important role. A tutorial
should not hide its concepts.
Best regards
Ralph
On 28.10.24 14:21, Reza Rahman via
jakarta.ee-community wrote:
I think the Tutorial refactoring work could
easily be tagged “good first issue” and “help wanted”. We
have a shockingly low number of those across EE4J projects.
Updating the Jakarta EE Tutorial to remove EJB when
possible
(3) is non-trivial since a lot of work needs
to be done upgrading/rewriting the examples in general,
but that doesn’t mean I can’t at least break that work
down into the issue tracker. Also, the intro (which I
rewrote) specifically does not mention EJB.
I’d like to add another: Writing an OpenRewrite for
migrating from EJB->CDI.
___
Kito
D. Mann | @kito99@mastodon.social | LinkedIn Java Champion | Google Developer Expert Alumni
Expert consulting and training: Cloud architecture and
modernization, Java/Jakarta EE, Web Components, Angular,
Mobile Web
Virtua, Inc. | virtua.tech
+1 203-998-0403
* Enterprise development, front and back. Listen to Stackd
Podcast.
* Speak at conferences? Check out SpeakerTrax.
I
am moving comments on my Jakarta EE 12 Google Doc
(https://docs.google.com/document/d/1U2qEqF9K969t5b3YuX4cwex5LJPvF3bt1w27cdKNpDM/edit?usp=sharing)
to Jakarta EE mailing lists when possible. The problem
with Google Docs
comments is that they do not scale very well, aren't very
readable on
smaller devices, and do not archive well. I will do so one
email per
comment. The person commenting is copied.
Context: Why does replacing EJB matter?
Josh Juneau (Community): Are there any comprehensive
tutorials on how to
utilize CDI rather than EJB for querying entities? It
seems like these
tutorials need to be made front and center in an effort to
help steer
people to CDI and to show that EJB is no longer needed in
many cases.
Reza Rahman (Microsoft): Good point. As of Jakarta EE 11,
it is indeed
possible to just use CDI now for basic CRUD in a
transactional and
thread safe manner with Jakarta Persistence. The same for
EJB
@Asynchronous and @Schedule. At the bare minimum, this is
worthy of an
Eclipse Foundation newsletter article and/or JakartaOne
talk. The
material could cover where EJB is not needed any more and
where it is
still needed. The title could be something attention
grabbing like -
"EJB is Dead, Long-Live CDI and Jakarta EE". We could also
ensure a
revised Jakarta EE 11 Tutorial can avoid using EJB when
possible. Maybe
Kito could comment on this? Additionally, the Marketing
Committee has
been sponsoring some guides. Could we consider already
starting an EJB
migration guide?