EJB and modern Java development

I am new to Java EE and see that EJBs are alive and well in the pure Java / Oracle community. However, everyone at work shows a disgusting look on their face when someone else says the phrase “EJB,” which makes me think that they either disappeared or were replaced by modern development teams using some other middleware technology.

How did the JSP give way to JSF-oriented viewing technologies, is the same true for EJB? In any case, what are the popular alternatives to EJB and how do they differ? What benefits or features do they offer at EJB?

+6
source share
3 answers

The first version of EJB was introduced back in the late 1990s.

A disgusting look at the face of your colleagues when EJB is mentioned may be the result of very complex and unpleasant patterns of using the first two versions of EJB (for example, complex xml deployment descriptors).

3.0 and 3.1 have been significant improvements in terms of usability.

Popular alternative to Spring framework + Hibernate / JPA

+9
source

Your colleagues may have seen only EJB2 and earlier versions that were truly unholy animals, which very few people used.

In EJB2, for the simplest things, a very invasive framework that was supposed to implement interfaces, with crazy life-cycle methods for which the developer had to provide an implementation, but the developer had nothing to do with the (business) goals. It was necessary to provide several such artifacts.

In addition, each bean must be stored in synchronization with records in a very detailed and hard to read deployment descriptor (XML file). As if this was not insulting enough for the developer, special tools should have been used to "improve" the bean and to create proxy classes, skeletons, and stubs. General OO things, such as inheritance, were not supported. There was some kind of injection, but strange, which existed in order to put things into some kind of map (actually a directory) associated with each bean.

The original EJB 1 model forcibly transferred all communications to the remote and all objects that should be distributed (EJBs were initially considered only remote access technology). To get the benefits of EJB, you were also forced to redistribute your architecture, even if it was completely unnecessary.

Perhaps the biggest insult to all was the concept of Entity bean (not to be confused with JPA entities). The bugs with this type of bean were so great that even the biggest supporters of EJB at that time could hardly recommend it to anyone.

Then, as a very practical issue, compatibility between EJB implementations was not very good, to say the least. Specifically, Entity Beans required a huge amount of vendor-specific configuration.

To cope with this, EJB implementation required supercomputers (in terms of installed sizes and required memory) of application servers, which were source locked and were quite expensive (thus not allowing companies to upgrade or switch because investments had to be returned first ) I don’t remember how many people wrote about technology at that time, and as far as I remember, the technology was mainly divorced by sales teams to managers of large corporations.

It is not surprising that the average developer did not really like this technology.

The sun realized just in time that the technology was moving in a completely wrong direction and was making a 180 ° turn and was embarking on large-scale reengineering work.

As a result, EJB 3 (2006) is a very smart and easy approach. No necessary interface interfaces are required for implementation, there is no XML required, only one bean must be encoded (just a simple POJO), standard default values ​​are used everywhere (conditional configuration), no special tools are needed (normal javac will do), and use Simple Beans locally is actually a common case.

The essence of the Beans was so erroneous that they were completely discarded and replaced by a much more robust approach, protected by TopLink and Hibernate among others.

Combine this with a wide selection of free, lightweight, and open source software, combined with many renowned technology bloggers (e.g. Adam Bien, Rezh Rahman, Gavin King), and the return to popularity is easy to explain.

Recently, several Spring for Java EE migration guides have appeared, and they have received a very favorable vote on various news sites, many of which express their support for EJB as a very good technology Now. That would have been unthinkable half a century ago (when EJB 3 was only released and was not yet very famous).

The most common alternative to EJB is Spring Core (Spring Beans). At the moment, I think that there are no significant Spring advantages for EJB and vice versa. The two technologies are very similar. Spring offers a few additional utilities, while EJB is conceptually lighter (without XML). Both benefits are somewhat subjective. They are usually inspired by each other, and who is a little ahead, often depends on which technology last released a major new version.

+14
source

When they were introduced, EJBs were the solution to finding the problem, and high-end on that.

The EJB was to provide a way for programs to determine the unit of work so that the application server containing the "EJB" would handle increasingly complex bits such as load balancing, location, failure, security, remote access, etc. In fact, when the developers all fired up in a brilliant new language, the implementations were not really ready for the whole difficult climb, they probably took advantage of the features, but the configuration and deployment were certainly a nightmare. It did not help that the EJB specification was in motion over time, and the performance of the primary use case candidate, Entity Bean, was severely deprived.

In my case, we developed an EJB to handle what has always been a batch process - get a set of transactions once a day, do some database materials, then send products to various interested parties and create reports. We don’t need threading or load balancing, not to mention most of the other EJB features. What was used most was a web-based approach to applications. The whold application could be done with some batch jobs and several web pages.

+2
source

Source: https://habr.com/ru/post/905544/


All Articles