Wednesday, November 11, 2026

JPA Architecture – Components and Relationships

1. JPA Architecture: The Components of

The diagram illustrates the main components of the Jakarta Persistence API (JPA) architecture and the relationships between them. It describes how persistence units are configured, how entity managers are created, and how persistence contexts are managed.


Component Description
Persistence The Persistence class provides static methods that allow an application to create an EntityManagerFactory for a particular persistence unit.
persistence.xml The persistence.xml file is the standard XML configuration file used to define persistence units. It can specify the entity classes participating in each persistence unit, the persistence provider, database connection information, and mapping files.
Persistence Unit A persistence unit is a logical group of entity classes and their persistence configuration. It defines which entities are managed and how the persistence provider should handle them.
It is used to configure the EntityManagerFactory and defines the entity model used by the persistence contexts created from it.
EntityManagerFactory An EntityManagerFactory is responsible for creating EntityManager instances. It can be created programmatically through the Persistence bootstrap class or provided by a Jakarta EE container. Its configuration is determined by the associated persistence unit.
An EntityManagerFactory is generally an expensive object to create and is designed to be reused by the application. Consequently, it is normally created once and shared by multiple components or threads.
EntityManager The EntityManager is the primary JPA interface through which an application interacts with the persistence layer.
An EntityManager is created by an EntityManagerFactory and is associated with a persistence context.
Persistence Context A persistence context is a set of managed entity instances associated with a particular persistence unit. Within a persistence context, each persistent entity identity corresponds to a unique managed entity instance. A persistence context tracks changes to managed entities and coordinates their synchronization with the database.

2. JPA Architecture: Associations and Multiplicities

2.1 persistence.xml - Persistence Unit

One persistence.xml file can define one or more persistence units. Each persistence unit is defined within one persistence configuration file.

2.2 Persistence - EntityManagerFactory

The Persistence class provides static factory methods that can be invoked multiple times to create EntityManagerFactory instances. Each invocation of createEntityManagerFactory() returns an entity manager factory associated with the specified persistence unit. (The one-to-many multiplicity in the diagram expresses the possibility of creating multiple factories through the same bootstrap mechanism.)

2.3 Persistence Unit - EntityManagerFactory

One persistence unit can be used to create multiple EntityManagerFactory instances. Each EntityManagerFactory is associated with one persistence unit.

2.4 Persistence Unit - Persistence Context

A persistence unit can serve multiple persistence contexts. Each persistence context uses the entity model defined by one persistence unit.

2.5 EntityManagerFactory - EntityManager

One EntityManagerFactory can create multiple EntityManager instances. Each entity manager is created by one factory.

2.5 EntityManager - Persistence Context

An entity manager interacts with its persistence context to perform persistence operations.

The multiplicity of the association between EntityManager and Persistence Context depends on the application environment and the type of persistence context being used.

2.5.1 Application-managed entity managers

In the typical application-managed scenario, the application explicitly creates an EntityManager using an EntityManagerFactory:

EntityManager em1 = emf.createEntityManager();
EntityManager em2 = emf.createEntityManager();

Each independently created application-managed EntityManager has its own persistence context. Therefore, the relationship is normally one-to-one: one EntityManager is associated with one persistence context and one persistence context belongs to one EntityManager. Creating another entity manager creates another persistence context.

2.5.2 Container-managed entity managers

In a Jakarta EE environment, the container manages entity managers and their persistence contexts.

When using transaction-scoped persistence contexts, multiple EntityManager references associated with the same persistence unit can share the same persistence context if they participate in the same JTA transaction.

For example, two application components can inject an EntityManager for the same persistence unit. If both components participate in the same transaction, their entity managers can share the same persistence context. In this case, multiple EntityManager references interact with one persistence context, which manages the entity instances for that transaction. Therefore, the relationship can be represented as many-to-one: multiple EntityManager references can share one persistence context.

However, this does not mean that all entity managers share the same persistence context. Sharing depends on the persistence unit and the transaction in which they participate.

3. Summary

JPA persistence architecture flow Persistence XML defines a persistence unit. The persistence unit configures an entity manager factory. The Persistence bootstrap class creates the factory. The factory creates entity managers, which interact with a persistence context. JPA Persistence Architecture persistence.xml defines Persistence Unit configures EntityManagerFactory Persistence creates bootstrap class creates EntityManager interacts with Persistence Context

The architecture can be understood through the following sequence:

  1. The persistence.xml file defines one or more persistence units.
  2. A persistence unit specifies the entity model and persistence configuration.
  3. The Persistence bootstrap mechanism creates an EntityManagerFactory for a persistence unit.
  4. The EntityManagerFactory creates one or more EntityManager instances.
  5. Each EntityManager manages a persistence context, although container-managed transaction-scoped persistence contexts can be shared by multiple entity manager references.
  6. The persistence context maintains the managed entity instances and coordinates their synchronization with the database.

The distinction between the EntityManagerFactory, the EntityManager, and the Persistence Context is fundamental to understanding JPA: the factory creates entity managers, entity managers manage persistence contexts, and persistence contexts maintain the managed entity instances.


Sources:

https://eclipse.dev/eclipselink/documentation/2.6/concepts/blocks002.htm

Thursday, June 18, 2026

Maven Dependencies and Spring Boot Starters

Maven projects use dependencies to include external libraries. If your Maven project is a Spring Boot application, you can use Spring Boot dependency starters. A Spring Boot dependency starter is a collection of related libraries that enables a specific capability in your application, such as building web applications, accessing databases or securing endpoints.

The "Most Common Production REST API" Stack

If you inspect a typical business API in 2026, you'll often see something close to:

Usual Name Dependency Name
Spring Web spring-boot-starter-web
Testing spring-boot-starter-test
Spring Data JPA spring-boot-starter-data-jpa
Validation spring-boot-starter-validation
Spring Security spring-boot-starter-security
Actuator spring-boot-starter-actuator
PostgreSQL Driver org.postgresql:postgresql
Lombok org.projectlombok:lombok

That set alone probably covers 70–80% of typical Spring Boot backend applications built for internal tools, SaaS products, e-commerce systems, and microservices.

Thursday, June 11, 2026

Introduction to Spring Boot and Spring MVC

0. Introduction

Client–Server Architecture

The client–server architecture is a distributed application structure that divides workloads between service providers (servers) and service consumers (clients).

  • A service is an abstraction over computing resources.
  • A server hosts one or more server programs and exposes services to clients.
  • Clients request services and servers process those requests.
  • The most common communication stack is TCP/IP.
  • Examples of client–server applications include email systems, network printing systems, and the World Wide Web.

Saturday, June 6, 2026

Naming Conventions for Java Classes

Naming Conventions for Classes in Spring / Jakarta Applications

For a modern Java application, developers use widely recognized naming conventions that make codebases easier to navigate.

Suppose you want to give a name to objects by what their class is responsible for. The table is organizing so that it show in the first column the purpose of the object and in the other columns convention to follow to give a name to a class.

A small caveat first:

  • @Service, @Repository, and @Controller are Spring stereotypes.
  • Jakarta EE does not provide direct equivalents for all of them.
  • In Jakarta EE, developers often use @ApplicationScoped, @RequestScoped, @Singleton or EJB annotations such as @Stateless.

So the mapping is sometimes exact, sometimes only conceptual.

Tuesday, June 2, 2026

Spring Framework Dependency Injection Complete Example

0. Introduction: Why using interfaces?

A Java interface defines a set of behaviors as abstract methods. A class that implements that interface has to fulfill those behaviors. An interface defines what happens, an object defines how it happens.
Interfaces allow to decouple implementations. This reduces dependencies between implementations and allows to change implementations independently.

Sample Analogy: Booking a Room

Suppose you are designing an application that allows customers to book hotel rooms. When a customer makes a reservation, they are not concerned with the name of the hotel; they are primarily interested in the destination city and the check-in and check-out dates. The room booking application therefore provides an interface in which the customer requests an accommodation, rather than a specific hotel.

Thursday, May 14, 2026

Introduction To Spring Framework

1.0 What is an application framework?

An application framework is a set of reusable components and functionalities that simplifies software development by removing the need for developers to build applications from scratch.

When developing applications, you usually distinguish between boilerplate code and business code.

  • Boilerplate code handles common technical needs shared by many applications, such as error logging, transaction management, security, inter-system communication, and performance optimizations such as caching and data compression. Synonims of boilerplate code are: plumbing code, framework code and infrastructure code.
  • Business code implements the use cases and specific requirements of an application—what users expect the application to do. It is what makes one application different from another.

A framework lets developers focus on business code by providing reusable solutions for common technical needs, reducing the amount of infrastructure code that must be written and maintained.

2.0 Spring as a collection of frameworks

Spring is a collection of frameworks and libraries, not just a single framework; therefore we say that Spring is an ecosystem.

The most common modules in the Spring Framework ecosystem are:

  • Spring Core – the foundational module that provides essential capabilities, including:

    • Spring Context – manages the lifecycle and configuration of objects (beans)
    • Spring AOP (Aspect-Oriented Programming) – intercepts and modifies method execution
    • Spring Expression Language (SpEL) – provides an expression language used in configuration and annotations
  • Spring MVC (Model-View-Controller) – provides the components needed to build web applications and RESTful web services.

  • Spring Data Access – provides support for working with relational databases and data access technologies.

  • Spring Testing – provides tools for writing and running tests for Spring applications.

Monday, October 6, 2025

Character Sets and Character Encodings

1 What is it a Character Set?

Character Set - Informal definition

A character set is just a collection of symbols (letters, digits, punctuation, emojis, etc.) that a computer system knows about, together with the numbers (code points) assigned to them.

Character Set - Formal definition

A character set (more precisely, a coded character set) is a mapping between a finite set of abstract characters and a set of unique code points (integers).

It defines:

  • Character repertoire = the set of characters included.
  • Code space = the range of assignable numeric values.
  • Mapping function = assigns each character exactly one code point.

Formally:

f : Character ↔ CodePoint ∈ CodeSpace

Where the code point is the single integer value that uniquely identifies one abstract character

Tuesday, August 26, 2025

Docker Commands to Run Containers

In this section, we see the docker commands for creating, stopping, restarting and deleting containers

TOC:

1 Check for existing containers and images

The Docker commands to list existing containers and images in your local Docker environment

You can use the docker ps command to list any running container

$ docker ps
CONTAINER ID      IMAGE     COMMAND    CREATED     STATUS    PORTS     NAMES

You can use the docker images command to list local images

$ docker images  
REPOSITORY        TAG         IMAGE ID       CREATED     SIZE

You’re on a clean system with no pre-existing containers or images.

Monday, August 11, 2025

Introduction to Docker

1 Introduction to Containers
2 How to Containerization
3 Images
4 Containers
5 Registries
6 Docker Architecture
7 Containers for Microservices


1 Intro to Containers

The problem containers are meant to solve

Applications work in different environments, such as many development environments, testing environments and production environments.
An application relies on various dependencies to function correctly. These may include: programming libraries (e.g., Apache Commons for Java, React for JavaScript), frameworks (e.g., Spring and Struts for Java, Angular for JavaScript), runtime environments (e.g., Node.js, Java JDK), external APIs or services (e.g., Amazon S3, Google APIs), and operating system packages.
A common problem with application deployment is that an application may work in one environment but fail in another; this is often due to different environments having different versions of the application's dependencies.
Containers fix this problem, because they create an way to package applications along with their dependencies, so you deploy to production the same things you have developed.

Definitions:

Term Definition
Docker image A Docker image is the standard Docker package for distributing and running applications.
Docker container A Docker container is a running instance of a Docker image, or the Docker standard unit of execution.
Docker engine The Docker engine is the full Docker platform you install on your machine or server. It includes the Docker Daemon (dockerd), Docker CLI (docker), the REST API and other components to build and run containers, such as container runtime (runc), image builder, storage drivers and networking layer. The Docker engine runs natively on Linux, whereas on macOS/Windows it runs inside a Linux virtual machine.
Open Container Initiative The Open Container Initiative (OCI) is an organization created in 2015 by Docker and other industry leaders. It defines the official specifications for containers. These specifications allow container tools built by different vendors to work well together. Example container tools include Docker (by Docker Inc.), containerd (by CNCF), Podman (by Red Hat), CRI-O (also Red Hat) and Kubernetes (by CNCF).

Monday, May 26, 2025

Online Food Store Case Study

STEP 1 - System Requirements Analysis

1.1 Main Use Case: Making an Order

Here you do an examination the different stages involved in the process of how to do an online order

  1. Browsing and Adding to Cart: The customer explores the online store, finds items they like, and adds them to their virtual shopping cart. When the customer is finished adding items, they requests the cart; they may optionally edit the cart.

  2. Order Checkout: The customer clicks "proceed to order" and enters their personal information, shipping address, and payment details. The customer reviews their order summary, including the items, quantity, price, and shipping details. They then click a button like "Confirm Order" or "Place Order" or "Buy Now" to finalize the purchase. This action sends the order request to the online store.

  3. Confirmation Email: The customer receives a confirmation email with a summary of the order details and an order number. The store is acknowledging that the order has been received and is being processed.

  4. Payment Processing: The online store processes the customer's payment, ensuring the funds are securely transferred.

  5. Order Fulfillment: The online store prepares the order for shipment. This includes picking the items, packing them, and generating a shipping label.

  6. Shipping: The order is handed over to the shipping carrier, which delivers it to the customer's address.

  7. Delivery: The customer receives their order!

  8. Order Completion: The online store marks the order as complete in their system.

  9. Potential Return/Refund: The customer may have the option to return or request a refund for their order if they are not satisfied.

1.2 "Making an Order" System Sequence Diagrams
CustomerSystemAdminrequestMenu"Menu"loopaddItemToCart(item)requestCart"Cart"checkoutOrder(cart)"Order"setDeliveryAddresssetPaymentDetailsplaceOrder(order)"Order Confirmation Email"notifyAdmin(orderId, "new order")approveOrder(orderId)notifyCustomer("order is being prepared")updateOrderStatus(orderId, "ready for delivery")notifyCustomer("order is ready for delivery")notifyCustomer("order is delivered")updateInventory(item, quantity)

STEP 2 - OOA: Functional Requirements Analysis

When doing OO analysis, you create the Domain Model and draw classes/abstractions and interactions.

2.1 Online Food Store Key Abstractions
  • Customer: The person placing the order.
  • Menu: The list of available MenuItem.
  • MenuItem: The dishes items the Customer selects from the Menu. MenuItem details: price, description and dietary info
  • Cart: The virtual cart where the customer adds their items.
  • Restaurant: The establishment providing the food.
  • Order: The collection of items the customer wants.
  • OrderItem: a single item within an order, including quantity and any special instructions.
  • Address: The Customer delivery address and the Restaurant location
  • RestaurantAdmin: The person who accepts orders and manages the order states
  • Payment Details: a class that holds the details of the payment method used.
  • Payment System: The system used to process the payment.
  • Delivery Service: The service responsible for delivering the food.
  • Review/Rating: To allow customers to rate their experience.
2.2 Online Food Store Domain Model
Menumenu itemsMenuItemnamepriceCartorder itemsadd(menuItem)OrderItema menu itema quantityOrdercustomerorder itemsshipping addresspayment methodstatusCustomerfirst namelast nameemaildate of birthphone numberAddressPaymentcontains11..*contains11..*has11is used to createis placed by1*has11..*has11has11

STEP 3 - OOD: Sequence Diagram

3.1 The Sequence Diagram of the "Making an Order" Use Case
CustomerMainUIControllerRestaurantCartOrderMailingSystemPaymentServicePaymentGatewayDeliveryServiceAdminUIAdminrequestMenu()requestMenu()requestMenu()"Menu""Menu"loopaddItemToCart(item)addItemToCart(item)addItemToCart(item)add(item)requestCart()requestCart()requestCart()"Cart""Cart"checkoutOrder(cart)checkoutOrder(cart)checkoutOrder(cart)"Order""Order"setDeliveryAddress(address)setDeliveryAddress(address)setDeliveryAddress(address)setDeliveryAddress(address)setPaymentDetails(payment)setPaymentDetails(payment)setPaymentDetails(payment)setPaymentDetails(payment)placeOrder(order)placeOrder(order)placeOrder(order)sendConfirmationEmail(order)"Order Confirmation Email"updateOrderStatus(orderId, "pending")processPayment(payment)processPayment(payment)paymentResult(success/failure)paymentConfirmation(success/failure)updatePaymentStatus(success/failure)notifyAdmin("new order")approveOrder(orderId)approveOrder(orderId)notifyCustomer("order is being prepared")updateOrderStatus(orderId, "accepted")updateOrderStatus(Id, "ready for delivery")updateOrderStatus(orderId, "ready for delivery")updateOrderStatus(orderId, "ready for delivery")notifyCustomer("order is ready for delivery")requestDelivery(order)deliveryConfirmation(success/failure)updateOrderStatus(orderId, "delivered")notifyCustomer("order is delivered")updateInventory(item, quantity)

STEP 4 - OOD: Class Diagram

4.1 The Refined Domain Model Class Diagram

The class diagram of the design activity which represents the Refined Domain Model

Menuitems : List<MenuItem>MenuItemname : Stringprice : DoubleCartitems : List<OrderItem>add(:MenuItem)OrderItemitem : MenuItemquantity : IntegerCustomercustomerID : LongfirstName : StringlastName : Stringemail : Stringphone : StringshippingAddresses : Address[]billingAddress : AddresspaymentMethods : Payment[]OrderorderID : Longitems : List<OrderItem>customer : CustomershippingAddress : AddresspaymentMethod : PaymentpaymentStatus : StringtotalAmount : DoubleorderStatus : StringAddressPaymentcontains11..*11..*is used to create11is placed by10..*1111..*has11