Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

EJB support in Piranha via CDI

Enterprise Beans was once the face of Java EE, but as we discussed a while ago, is currently de-emphasised in Jakarta EE. However, since there’s so much existing code using Enterprise Beans, a certain level of support is still desired.

Piranha Cloud, a relatively new runtime supporting Jakarta EE, takes a somewhat novel approach to Enterprise Beans. Instead of implementing a separate container, Piranha Cloud, via the OmniBeans project, maps Enterprise Beans annotations to equivalent functionality in CDI itself, or to technologies in Jakarta EE leveraging CDI (such as Jakarta Transactions). Enterprise Beans features not currently present in Jakarta EE, such as the pooled concept for Stateless beans, are provided by the OmniServices library.

An overview of the mappings is depicted in the following diagram:

OmniBeans primarily consists out of a CDI extension, that observes the ProcessAnnotatedType event. When it encounters say the @Stateless annotation on a bean it adds @Pooled from OmniServices, and depending on any @jakarta.ejb.TransactionAttribute and/or @jakarta.ejb.TransactionManagement annotation the @jakarta.transaction.Transactional annotation from Jakarta Transactions.

Piranha Cloud uses the standalone and pluggable Jakarta Transactions implementation Transact (which originates from GlassFish) for the code behind the @Transactional annotation. For the @Asynchronous annotation OmniServices is currently used, but in the future a pluggable Jakarta Concurrency implementation should be used for this. The “Concurrency RI” project is a likely candidate to base such an implementation on (with the proposed name Concurro).

The development of OmniBeans is still in its early days, but it’s already able to pass a test taken from the EJB Lite TCK, which is the stateless-tx test. This contains beans such as the following:

@Stateless
public class TxBean {

    @PersistenceContext(unitName = "ejblite-pu")
    private EntityManager entityManager;

    /*
     * @testName: supports
     *
     * @test_Strategy:
     */
    @TransactionAttribute(SUPPORTS)
    public void supports(CoffeeEntity coffeeEntity, boolean flush) {
        updatePersist(coffeeEntity, flush);
    }

    // [...]

    protected void updatePersist(CoffeeEntity coffeeEntity, boolean flush) {
        coffeeEntity.setPrice(coffeeEntity.getPrice() + 100);
        entityManager.persist(coffeeEntity);

        if (flush) {
            entityManager.flush();
        }
    }

}

and

@Stateless
@TransactionManagement(BEAN)
public class TestBean {

    private EntityManager entityManager;
    private UserTransaction userTransaction;

    private TxBean txBean;

    @PersistenceContext(unitName = "ejblite-pu")
    public void setEm(EntityManager entityManager) {
      this.entityManager = entityManager;
    }

    @Resource
    public void setUt(UserTransaction userTransaction) {
      this.userTransaction = userTransaction;
    }

    @EJB(beanInterface = TxBean.class)
    public void setTxBean(TxBean b) {
        txBean = b;
    }
}

As can be seen, those beans are far from trivial from a technical perspective. The fact that OmniBeans is already able to pass such a test bodes well for the future. 

Hopefully at some point it will be able to fully pass the entire EJB Lite TCK this way, which would make for a very interesting Enterprise Beans implementation.

P.s.

If you have some time, please complete the OmniFish survey to help us prioritise what we should do for Jakarta EE 11

Leave a Comment

Your email address will not be published. Required fields are marked *

Protected by BestWebSoft Captcha