Week 1

Enterprise Computing & Jakarta EE

Part I: Introduction to Jakarta EE
Part II: Jakarta Persistence API

Stephen Vu — Tutor

Your Tutor

Stephen Vu

PhD in Artificial Intelligence, Queensland University of Technology (QUT)

Academic Experience

4 Years Teaching Across 4 Universities

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.

Industry Experience

AI & Data Science in Production

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.

What to expect: Each week combines lecture theory with hands-on lab projects. You will write real code, configure real servers, and debug real problems. Come prepared, ask questions, and don't be afraid to break things — that's how you learn.

Before We Begin

Why Study Enterprise Computing?

Industry Demand

It's Where the Jobs Are

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.

Architectural Thinking

Beyond Single-File Programs

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.

Transferable Skills

Patterns That Persist

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.

Bottom line: This unit transforms you from someone who can write code into someone who can build systems.
I

Introduction to Jakarta EE

Understanding why enterprise platforms exist and how Jakarta EE addresses the challenges of modern software development.

Part I

Learning Objectives

1

Enterprise Challenges

Identify the core challenges that modern enterprise software must solve — from distributed data access to security and scalability.

2

Jakarta EE's Role

Recognise how Jakarta EE provides a standardised platform to develop enterprise applications using well-defined APIs and containers.

3

Application Scenario

Understand the CD-BookStore application that will serve as our running case study throughout the entire unit.

The Problem

The Enterprise Challenge

Access data across distributed networks
Apply complex business logic
Handle multiple currencies & time zones
Enterprise
Application
Serve web & mobile interfaces
Integrate with legacy systems
Communicate with external services

Enterprises need software that is reliable, available, scalable, and secure — all at once.

The Solution

What Is Jakarta EE?

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.

Key Standard APIs

JTATransaction management
JMSAsynchronous messaging
JPAData persistence (ORM)
EJBBusiness components
JSFWeb presentation layer

Evolution

Jakarta EE History

From J2EE to Jakarta EE — a platform that evolved from heavyweight complexity to developer-friendly simplicity.

1999
J2EE 1.2
Platform launched
2006
Java EE 5
Annotations introduced
2009
Java EE 6
POJO model, config by exception
2013
Java EE 7
WebSocket, Batch, JSON, CDI
2017
Java EE 8
JSON-B, Security API
2019
Jakarta EE 8
Moved to Eclipse Foundation
2022
Jakarta EE 10
Cloud-native, namespace change
Key shift: Java EE 6 (2009) was the turning point — annotations replaced XML configuration, and POJOs replaced heavyweight components. Development became dramatically simpler.

Architecture

Jakarta EE Architecture

Jakarta EE is organised into containers — runtime environments that host components, manage their lifecycle, and provide services like security, transactions, and dependency injection.

Client Tier

Browser, Desktop App, Mobile

Web Container

Servlets, JSP, JSF pages

EJB Container

Enterprise Beans, JMS, JTA

Services Layer

Transactions • Security • Persistence • Naming • Concurrency

Database / EIS Tier

Relational DB, Legacy Systems, External Services

Architecture

Jakarta EE Components

The runtime environment defines four types of components. In this unit, we focus on Web Applications and Enterprise Applications.

Legacy

Applets

GUI applications executed in a web browser. Largely deprecated in modern development.

Client-Side

Application Clients

Desktop programs executed on a client machine with access to EJB containers via RMI-IIOP.

This Unit — Weeks 8-10

Web Applications

Built with Servlets, JSP, and JSF. Run in the web container and respond to HTTP requests from browsers and mobile clients.

This Unit — Weeks 5-7

Enterprise Applications

Built with EJBs, JMS, JTA. Run in the EJB container. Accessed locally or remotely via RMI, SOAP, or RESTful services.

Architecture

Containers & Their Responsibilities

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
Key idea: Components don't manage their own lifecycle, security, or transactions. The container does it for them. This is what "managed environment" means.

Deployment

Jakarta EE Packaging

Components must be packaged into standard archive formats before deployment. Each format serves a specific purpose.

.jar — Java Archive

Classes, resources, EJB modules
META-INF/ejb-jar.xml

.war — Web Archive

Servlets, JSP, JSF, HTML, CSS, JS
WEB-INF/web.xmlWEB-INF/classes/WEB-INF/lib/

.ear — Enterprise Archive

Contains .war + .jar modules + shared libraries
META-INF/application.xmllib/

Think of It Like Nested Containers

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.

Knowledge Checkpoint

Quiz — Part I: Jakarta EE Basics

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?

Unit Structure

What We'll Build This Semester

The unit follows the three tiers of an enterprise application, building from the bottom up.

Weeks 1–4
Persistence Tier (JPA)
Weeks 5–7
Business Tier (EJB)
Weeks 8–10
Presentation Tier (JSF)
Weeks 11–12
REST & Microservices

CD-BookStore Application

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.

Actors in the System

CustomerBrowse, buy, manage account
EmployeeManage catalog & orders
AnonymousBrowse catalog, create account
BankCredit card validation

Part I Recap

Summary — Introduction to Jakarta EE

Enterprise applications must handle

Reliable data access, transaction management, security, concurrency, messaging, and integration with distributed systems — simultaneously.

Jakarta EE is an industry standard

A suite of APIs and specifications (not a single product) that provides standardised solutions for common enterprise concerns.

Components deploy to containers

The Web Container hosts servlets and JSF; the EJB Container hosts business logic. Both provide lifecycle management, security, and transactions.

Standard packaging formats

.jar for classes, .war for web modules, .ear for full enterprise applications — all following defined directory structures.

II

Jakarta Persistence API

Bridging the gap between Java objects and relational databases through Object-Relational Mapping.

Part II

Learning Objectives

1

Data Persistence & JPA

Understand why persisting objects to relational databases is a fundamental challenge, and how JPA solves it.

2

Entities & ORM

Define JPA entities and understand how object-relational mapping bridges the Java and SQL worlds.

3

Lifecycle & Callbacks

Trace the entity lifecycle from creation through persistence, and hook custom logic into lifecycle events.

The Problem

Two Different Worlds

Object-oriented programming and relational databases use fundamentally different models. This mismatch is called the impedance mismatch.

Object World (Java)

  • Classes & objects
  • Inheritance hierarchies
  • References & collections
  • Encapsulated state & behaviour
  • Identity via memory reference
  • Polymorphism

Relational World (SQL)

  • Tables, rows & columns
  • No inheritance concept
  • Foreign keys & join tables
  • Data only — no behaviour
  • Identity via primary keys
  • Normalisation rules

JPA's job is to make these two worlds work together transparently.

Approaches

How Java Persists Data

There are three main approaches to persistence in Java. Each has its place, but JPA (ORM) is the preferred approach for enterprise applications.

Limited

Serialization

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

Low-Level

JDBC

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

Preferred

JPA (ORM)

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

Jakarta Persistence API — The Big Picture

JPA is an abstraction above JDBC that makes your code independent of SQL. All classes reside in the jakarta.persistence package.

Object-Relational Mapping

Map Java classes to database tables using annotations. Fields become columns, objects become rows.

EntityManager API

Perform CRUD operations — persist(), find(), merge(), remove() — without writing SQL.

JPQL

Query using object-oriented syntax: SELECT b FROM Book b WHERE b.title = 'H2G2'

Transactions & Locking

Manage concurrent access to data through JTA (container-managed) or resource-local transactions, with optimistic and pessimistic locking strategies.

Callbacks & Listeners

Hook custom business logic into entity lifecycle events — run code before/after an entity is persisted, updated, removed, or loaded.

Core Concept

What Is an Entity?

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.

Configuration by exception: JPA applies sensible defaults. For example, the table name defaults to the class name. You only add annotations when you want to override the default.
@Entity @Table(name = "MyFavouriteBook") public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(name = "Book_Title", nullable = false, updatable = false) private String title; private Float price; private String description; private String isbn; private Integer nbOfPage; private Boolean illustrations; }

Mapping

How Entities Map to Tables

The persistence provider reads your annotations and creates a correspondence between Java fields and database columns.

Java Entity

Book.class MYFAVOURITEBOOK
Long id ID (bigint, PK)
String title BOOK_TITLE (varchar)
Float price PRICE (float)
String description DESCRIPTION (varchar)
String isbn ISBN (varchar)
Integer nbOfPage NUMBER_OF_PAGES (int)
Boolean illustrations ILLUSTRATIONS (tinyint)

Metadata Formats

Annotations (Preferred)

Metadata lives directly in the Java source code using @Entity, @Table, @Column, etc. This is the modern approach.

XML Descriptors (Alternative)

Mapping defined in an external XML file deployed alongside the entities. Useful when you cannot modify source code.

Querying

The EntityManager

The EntityManager is the central API for all persistence operations. It hides JDBC entirely — you never write SQL directly.

// Create an instance of Book Book book = new Book(); book.setTitle("The Hitchhiker's Guide"); book.setPrice(12.5f); book.setDescription("Science fiction"); book.setIsbn("1-84023-742-2"); book.setNbOfPage(354); // Get an EntityManager EntityManagerFactory emf = Persistence.createEntityManagerFactory( "W1P1PU"); EntityManager em = emf.createEntityManager(); // Persist the book in a transaction EntityTransaction tx = em.getTransaction(); tx.begin(); em.persist(book); tx.commit();

What Happens Behind the Scenes

em.persist(book) triggers an INSERT INTO MYFAVOURITEBOOK ... SQL statement — but you never see it. The EntityManager handles the mapping, connection, and execution.

Key EntityManager Methods

persist()INSERT — save new entity
find()SELECT — retrieve by primary key
merge()UPDATE — sync detached entity
remove()DELETE — remove entity

JPQL Queries

Object-oriented query syntax using entity names and field names, not table/column names:

SELECT b FROM Book b WHERE b.title = 'H2G2'

Knowledge Checkpoint

Quiz — Entities & ORM

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?

Lifecycle

Entity Lifecycle

Entities are POJOs. They only gain a persistence identity when the EntityManager begins managing them. Here are the four states:

NEW
— em.persist() →
MANAGED
↓ em.detach() / close()
REMOVED
← em.remove() —
DETACHED
↑ em.merge() returns to MANAGED
New: Created with new Book(). JPA doesn't know about it. Can be garbage collected.
Managed: After persist() or find(). Changes are automatically synced to the database.
Detached: EntityManager is closed or entity is explicitly detached. Changes are NOT tracked.
Removed: After remove(). Data is deleted from DB but the Java object still exists in memory.

Events

Callbacks & Listeners

JPA lets you hook business logic into entity lifecycle events. Think of them as database triggers, but in Java.

OperationBeforeAfter
Persist (INSERT) @PrePersist @PostPersist
Update (UPDATE) @PreUpdate @PostUpdate
Remove (DELETE) @PreRemove @PostRemove
Load (SELECT) @PostLoad

Two Ways to Use Them

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.

Common use cases: Setting timestamps on creation/update, validating data before persistence, auditing changes, sending notifications after removal.

Part II Recap

Summary — Jakarta Persistence API

The impedance mismatch

Objects and relational tables use different paradigms. JPA bridges this gap through ORM — you work with objects, JPA handles the SQL.

Entities are annotated POJOs

Use @Entity, @Id, @Table, @Column to map classes to tables. Configuration by exception means defaults handle most cases.

EntityManager is the central API

persist(), find(), merge(), remove() handle all CRUD operations. JPQL provides object-oriented querying.

Entities have a lifecycle

New → Managed → Detached → Removed. Callbacks (@PrePersist, @PostLoad, etc.) let you hook business logic into state transitions.

Knowledge Checkpoint

Final Quiz — Full Week 1 Review

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?

End of Week 1

Next Up: Lab Projects

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.