This lesson provides an overview of how modern Jakarta EE applications handle data persistence and transactional integrity using the Jakarta Persistence API (JPA) and container-managed transaction services. It updates the legacy concepts of âEntity Beansâ and âJ2EEâ to reflect todayâs simplified and annotation-driven approach to enterprise development.
This module introduces the fundamental components of enterprise persistence and security in Jakarta EE. You will explore three interconnected areas:
Early versions of J2EE used Entity Beans to represent persistent data. Developers managed persistence either through Bean-Managed Persistence (BMP) or Container-Managed Persistence (CMP). These models required verbose configuration and tightly coupled business logic with data access. Jakarta EE replaces these legacy mechanisms with JPA entities-lightweight POJOs (Plain Old Java Objects) annotated with @Entity and integrated into the persistence context.
Modern persistence units are defined through persistence.xml or annotations such as @PersistenceContext, allowing developers to focus on domain modeling rather than low-level database handling.
Enterprise applications often coordinate updates across multiple databases or message systems. The Jakarta Transactions API (JTA) provides a unified transaction interface for these scenarios. Container-managed transactions (CMT) are typically preferred, as the Jakarta EE container automatically begins, commits, or rolls back transactions based on method-level annotations such as @Transactional or @TransactionAttribute.
// Example: Container-managed transaction using JPA and JTA
@Stateless
public class AccountService {
    @PersistenceContext
    private EntityManager em;
    @Transactional
    public void transferFunds(Long fromId, Long toId, BigDecimal amount) {
        Account from = em.find(Account.class, fromId);
        Account to = em.find(Account.class, toId);
        from.withdraw(amount);
        to.deposit(amount);
    }
}
In this example, the container ensures that both database updates occur within a single atomic transaction. If any part fails, the entire operation is rolled back automatically.
Jakarta EE integrates with enterprise security realms and declarative authorization mechanisms. You can secure methods with annotations like @RolesAllowed, ensuring that only authenticated users with appropriate roles can invoke specific EJB or REST endpoints. The Jakarta Security API further unifies authentication across web and enterprise tiers.
After completing this course, you will be able to:
The concepts in this lesson build directly on CDI Managed Beans. Together, these modules form the foundation of modern enterprise architecture under Jakarta EE, replacing the older J2EE approach while maintaining the core principles of modularity, transaction integrity, and security.