Skip to main content

Jakarta EE

Jakarta EE — enterprise Java platform standard (formerly Java EE)

Hibernate Validator + CDI: When @Inject Actually Works Inside a Validator

The same ConstraintValidator, built two ways: Validation.buildDefaultValidatorFactory() throws a NullPointerException on an @Inject field it never processes, while a real Weld SE CDI container resolves the same field correctly. This post isolates exactly which ValidatorFactory makes @Inject real inside Hibernate Validator.

Master Java Bean Validation with Hibernate Validator 7: A Complete Guide

Have you ever spent hours debugging a "NullPointerException" or a corrupted database entry only to realize the data was malformed from the start? Manually writing if (user.getName() == null) checks across your entire service layer is not just tedious—it's a maintenance nightmare that leads to "spaghetti code." In the world of modern Java development, ensuring data integrity is paramount. This is where Java Bean Validation with Hibernate Validator 7 comes into play, providing a robust, annotation-based framework to handle constraints elegantly. In this guide, we’ll dive deep into how Hibernate Validator (the reference implementation of Jakarta Bean Validation) works with Hibernate 7 to keep your data clean and your code concise. The Problem: The "Validation Logic" Chaos Imagine a registration form for a high-traffic application. You need to ensure: The username isn't empty. The email is valid and follows global standards. The age is at least 18. The password meets complex security requirements (uppercase, digits, special characters). Without a centralized system, you end up duplicating this logic in your REST controllers, your service layer, and sometimes even at the database level using DDL constraints. This inconsistency leads to "Validation Drift," where one part of the app accepts data that another part rejects. This results in inconsistent system states, obscure runtime errors, and a poor user experience. The Agitation: Maintenance Debt and Data Corruption As your application grows, managing manual validation becomes a massive bottleneck. If the business requirement for a "valid phone number" changes to include international formats, you have to find every single if statement across dozens of files. Miss one? You’ve just introduced a security vulnerability or a data integrity issue that could poison your database for months.

Bootstrapping EntityManager in Hibernate 7 (Jakarta Persistence 3.2) – XML vs Programmatic Guide

Every other Hibernate article on this blog runs inside Spring Boot's auto-configured EntityManagerFactory. This rewrite steps outside it: real XML bootstrapping via persistence.xml, and Jakarta Persistence 3.2's new programmatic PersistenceConfiguration builder, verified via javap against the real jar. The centerpiece is a claim checked two independent ways -- does reusing a persistence-unit name pull in that unit's XML settings? A native SELECT DATABASE() query and Hibernate's own duplicate bootstrap log entries both confirm it doesn't. Also corrects a stale javax.persistence.PersistenceException claim to the real jakarta.persistence.PersistenceException, and measures what an EntityManagerFactory actually costs to build.