Part I: Introduction to Jakarta EE
Part II: Jakarta Persistence API
PhD in Artificial Intelligence, Queensland University of Technology (QUT)
Queensland University of Technology (QUT)
Kaplan Business School
James Cook University
Central Queensland University
Across these institutions, I've taught programming, data science, and enterprise systems to students at every level — from first-year introductions to advanced postgraduate units.
AI Specialist — Telstra
Researcher — Centre of Data Science, Queensland
I bring real industry perspective to this unit. The architectural patterns you'll learn here — persistence layers, service tiers, API design — are exactly what large-scale production systems are built on.
The majority of professional software development happens at the enterprise level. Banks, hospitals, airlines, governments — they all run on enterprise platforms. Understanding this ecosystem makes you employable.
University projects are often single-tier applications. Enterprise systems are distributed, multi-tier, and must handle thousands of concurrent users. This unit teaches you to think in layers and services.
Even if you never write Jakarta EE in your career, the patterns you'll learn — ORM, dependency injection, MVC, REST — appear in every modern framework: Spring, .NET, Django, Rails. Learn the concepts once, apply them everywhere.
Understanding why enterprise platforms exist and how Jakarta EE addresses the challenges of modern software development.
Identify the core challenges that modern enterprise software must solve — from distributed data access to security and scalability.
Recognise how Jakarta EE provides a standardised platform to develop enterprise applications using well-defined APIs and containers.
Understand the CD-BookStore application that will serve as our running case study throughout the entire unit.
Enterprises need software that is reliable, available, scalable, and secure — all at once.
Jakarta EE is a set of specifications designed for building enterprise applications. It extends Java SE to support distributed, robust, and highly available systems.
It is not a single product — it's an industry standard. Multiple vendors (Eclipse, Red Hat, Oracle) provide implementations that all follow the same specification.
Jakarta EE gives developers a standard way to handle concerns that every enterprise application faces, so they don't have to reinvent solutions for common problems.
| JTA | Transaction management |
| JMS | Asynchronous messaging |
| JPA | Data persistence (ORM) |
| EJB | Business components |
| JSF | Web presentation layer |
From J2EE to Jakarta EE — a platform that evolved from heavyweight complexity to developer-friendly simplicity.
Jakarta EE is organised into containers — runtime environments that host components, manage their lifecycle, and provide services like security, transactions, and dependency injection.
Browser, Desktop App, Mobile
Servlets, JSP, JSF pages
Enterprise Beans, JMS, JTA
Transactions • Security • Persistence • Naming • Concurrency
Relational DB, Legacy Systems, External Services
The runtime environment defines four types of components. In this unit, we focus on Web Applications and Enterprise Applications.
GUI applications executed in a web browser. Largely deprecated in modern development.
Desktop programs executed on a client machine with access to EJB containers via RMI-IIOP.
Built with Servlets, JSP, and JSF. Run in the web container and respond to HTTP requests from browsers and mobile clients.
Built with EJBs, JMS, JTA. Run in the EJB container. Accessed locally or remotely via RMI, SOAP, or RESTful services.
Containers hide technical complexity and provide services to deployed components. Think of them as managed runtime environments.
| Container | What It Hosts | Key Services | Protocol |
|---|---|---|---|
| Web Container | Servlets, JSP, JSF, Filters | HTTP handling, session management, security | HTTP / HTTPS |
| EJB Container | Session Beans, MDBs | Transactions, concurrency, security, distribution, async invocation | RMI-IIOP |
| App Client Container | Desktop applications | Injection, security, naming service | RMI-IIOP, HTTP |
| Applet Container | Browser-based applets | Sandbox security model | HTTP |
Components must be packaged into standard archive formats before deployment. Each format serves a specific purpose.
Classes, resources, EJB modulesMETA-INF/ejb-jar.xml
Servlets, JSP, JSF, HTML, CSS, JSWEB-INF/web.xml • WEB-INF/classes/ • WEB-INF/lib/
Contains .war + .jar modules + shared librariesMETA-INF/application.xml • lib/
A .ear file is the outer box. Inside it, you find .war files (web modules) and .jar files (EJB modules), plus a shared lib/ directory for common dependencies.
All three formats are essentially ZIP files with a specific internal directory structure and an optional XML deployment descriptor.
This is one of the first things that confuses students — learn the hierarchy early.
1. Which of the following is NOT a concern that Jakarta EE is designed to address?
2. What is the primary role of a Jakarta EE container?
3. Which packaging format contains both web modules and EJB modules?
The unit follows the three tiers of an enterprise application, building from the bottom up.
Throughout the course, we build a complete e-commerce application. Customers browse a catalog, purchase books and CDs, and the system communicates with an external bank for payment validation. Employees manage the catalog and orders.
| Customer | Browse, buy, manage account |
| Employee | Manage catalog & orders |
| Anonymous | Browse catalog, create account |
| Bank | Credit card validation |
Reliable data access, transaction management, security, concurrency, messaging, and integration with distributed systems — simultaneously.
A suite of APIs and specifications (not a single product) that provides standardised solutions for common enterprise concerns.
The Web Container hosts servlets and JSF; the EJB Container hosts business logic. Both provide lifecycle management, security, and transactions.
.jar for classes, .war for web modules, .ear for full enterprise applications — all following defined directory structures.
Bridging the gap between Java objects and relational databases through Object-Relational Mapping.
Understand why persisting objects to relational databases is a fundamental challenge, and how JPA solves it.
Define JPA entities and understand how object-relational mapping bridges the Java and SQL worlds.
Trace the entity lifecycle from creation through persistence, and hook custom logic into lifecycle events.
Object-oriented programming and relational databases use fundamentally different models. This mismatch is called the impedance mismatch.
JPA's job is to make these two worlds work together transparently.
There are three main approaches to persistence in Java. Each has its place, but JPA (ORM) is the preferred approach for enterprise applications.
Converts an object to a byte stream via java.io.Serializable. Simple, but offers no query language, no concurrent access, and no transactional support.
Good for: caching, simple file storage
Direct SQL execution through the standard Java Database Connectivity API. Powerful but verbose — you write raw SQL, manage connections, and manually map results to objects.
Good for: fine-grained control, legacy systems
Object-Relational Mapping delegates the database interaction to a framework. You work with Java objects; the persistence provider handles the SQL transparently.
Good for: enterprise applications, rapid development
JPA is an abstraction above JDBC that makes your code independent of SQL. All classes reside in the jakarta.persistence package.
Map Java classes to database tables using annotations. Fields become columns, objects become rows.
Perform CRUD operations — persist(), find(), merge(), remove() — without writing SQL.
Query using object-oriented syntax: SELECT b FROM Book b WHERE b.title = 'H2G2'
Manage concurrent access to data through JTA (container-managed) or resource-local transactions, with optimistic and pessimistic locking strategies.
Hook custom business logic into entity lifecycle events — run code before/after an entity is persisted, updated, removed, or loaded.
An entity is a Java object that lives briefly in memory and persistently in a database. It has the ability to be mapped to a database table.
Once an entity class is properly annotated, JPA can manage it — persisting it, querying it, updating it, and removing it from the database.
The term "entity" is preferred over "object" when discussing persistence, because it implies database awareness.
The persistence provider reads your annotations and creates a correspondence between Java fields and database columns.
Metadata lives directly in the Java source code using @Entity, @Table, @Column, etc. This is the modern approach.
Mapping defined in an external XML file deployed alongside the entities. Useful when you cannot modify source code.
The EntityManager is the central API for all persistence operations. It hides JDBC entirely — you never write SQL directly.
em.persist(book) triggers an INSERT INTO MYFAVOURITEBOOK ... SQL statement — but you never see it. The EntityManager handles the mapping, connection, and execution.
persist() | INSERT — save new entity |
find() | SELECT — retrieve by primary key |
merge() | UPDATE — sync detached entity |
remove() | DELETE — remove entity |
Object-oriented query syntax using entity names and field names, not table/column names:
SELECT b FROM Book b WHERE b.title = 'H2G2'
4. What annotation marks a Java class as a JPA entity?
5. What does "configuration by exception" mean in JPA?
6. Which EntityManager method is used to save a new entity to the database?
Entities are POJOs. They only gain a persistence identity when the EntityManager begins managing them. Here are the four states:
new Book(). JPA doesn't know about it. Can be garbage collected.
persist() or find(). Changes are automatically synced to the database.
remove(). Data is deleted from DB but the Java object still exists in memory.
JPA lets you hook business logic into entity lifecycle events. Think of them as database triggers, but in Java.
| Operation | Before | After |
|---|---|---|
| Persist (INSERT) | @PrePersist |
@PostPersist |
| Update (UPDATE) | @PreUpdate |
@PostUpdate |
| Remove (DELETE) | @PreRemove |
@PostRemove |
| Load (SELECT) | — | @PostLoad |
Callbacks: Annotate methods directly on the entity class. Simple and co-located with the entity code.
Listeners: Define logic in a separate class and attach it with @EntityListeners. Better separation of concerns.
Objects and relational tables use different paradigms. JPA bridges this gap through ORM — you work with objects, JPA handles the SQL.
Use @Entity, @Id, @Table, @Column to map classes to tables. Configuration by exception means defaults handle most cases.
persist(), find(), merge(), remove() handle all CRUD operations. JPQL provides object-oriented querying.
New → Managed → Detached → Removed. Callbacks (@PrePersist, @PostLoad, etc.) let you hook business logic into state transitions.
7. An entity in the "Detached" state means:
8. Which JPQL query correctly retrieves all books with a price greater than 20?
9. Which callback annotation would you use to set a "createdDate" timestamp automatically when saving a new entity?
Part 1: Setting up your Jakarta EE environment (JDK, MySQL, NetBeans)
Part 2: Building your first JPA project — persisting a Book entity
Make sure MySQL is running before you begin the lab. Come with questions next week.