You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/hibernate-orm.adoc
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1510,3 +1510,81 @@ Format mappers *must* have both `@PersistenceUnitExtension` and either `@JsonFor
1510
1510
1511
1511
Having multiple JSON (or XML) format mappers registered for the same persistence unit will result in an exception, because of the ambiguity.
1512
1512
====
1513
+
1514
+
[[validator_integration]]
1515
+
== Validation modes and Hibernate Validator integration
1516
+
1517
+
Hibernate Validator integration into Hibernate ORM opens up the following capabilities:
1518
+
1519
+
- performing entity validation on lifecycle events
1520
+
- applying constraint information from entities to DDL
1521
+
1522
+
From Quarkus's perspective, this is controlled by the <<quarkus-hibernate-orm_quarkus-hibernate-orm-validation-mode,`quarkus.hibernate-orm.validation.mode` configuration property>>.
1523
+
The available validation modes are:
1524
+
1525
+
- `auto` -- the default option; works the same as `callback` and `ddl` enabled simultaneously
1526
+
when the Jakarta Validation provider is available (i.e. the Hibernate Validator extension is enabled),
1527
+
and as `none` if no provider is available.
1528
+
- `callback` -- Hibernate Validator will perform the lifecycle event validation.
1529
+
- `ddl` -- Jakarta Validation constraints will be considered for the DDL operations
1530
+
- `none` -- Jakarta Validation integration will be disabled.
1531
+
1532
+
While all constraints with corresponding Jakarta Validation rules will apply during the `callback` validation,
1533
+
in the `ddl` mode, only a subset of constraints is used to influence the DDL.
1534
+
In the Hibernate Validator documentation, you can find link:{hibernate-validator-docs-url}#section-builtin-constraints[the list of available constraints] and their impact on the DDL generation.
1535
+
1536
+
Let's consider having a simple entity with some constraints applied to its properties:
1537
+
1538
+
[source,java]
1539
+
----
1540
+
import jakarta.validation.constraints.NotEmpty;
1541
+
import jakarta.validation.constraints.NotNull;
1542
+
import jakarta.validation.constraints.Size;
1543
+
1544
+
@Entity
1545
+
public class MyEntity {
1546
+
@Id
1547
+
public long id;
1548
+
1549
+
@NotNull
1550
+
@NotEmpty
1551
+
@Size(max = 50)
1552
+
public String name;
1553
+
1554
+
public String value;
1555
+
}
1556
+
----
1557
+
1558
+
With the `ddl` mode enabled, the resulting schema would be expected to have the following constraints:
1559
+
[source,sql]
1560
+
----
1561
+
create table myentity
1562
+
(
1563
+
id bigint not null primary key,
1564
+
name varchar(50) not null, // <1>
1565
+
value varchar(255), // <2>
1566
+
);
1567
+
----
1568
+
<1> The `name` column has a `not null` constraint because of the `@NotNull` constraint,
1569
+
and the length of the values is limited to `50` because of the `@Size(max=50)` constraint.
1570
+
+
1571
+
<2> Since the `value` property in the entity has no constraints, there are no additional constraints in the DDL,
1572
+
and the `255` length limit comes from the default `jakarta.persistence.Column#lenght()`.
1573
+
1574
+
With the `callback` mode, expect getting a `jakarta.validation.ConstraintViolationException` thrown:
0 commit comments