From 7fec477bc2e993de910b8a906c70f15373e3eac7 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Mon, 4 Nov 2024 22:10:21 +0100 Subject: [PATCH] HHH-18809 update Javadoc with this usage Signed-off-by: Gavin King --- .../main/java/org/hibernate/annotations/Formula.java | 9 +++++++++ .../main/java/org/hibernate/annotations/Generated.java | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/Formula.java b/hibernate-core/src/main/java/org/hibernate/annotations/Formula.java index c8cc6e9963b0..3ee1ab2eb9f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/Formula.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/Formula.java @@ -32,6 +32,15 @@ * Character middleInitial; * *

+ * By default, the fields of an entity are not updated with the results of evaluating + * the formula after an {@code insert} or {@code update}. The {@link Generated @Generated} + * annotation may be used to specify that this should happen: + *

+ * @Generated  // evaluate the formula after an insert
+ * @Formula("sub_total * (1.0 + tax)")
+ * BigDecimal totalWithTax;
+ * 
+ *

* For an entity with {@linkplain jakarta.persistence.SecondaryTable secondary tables}, * a formula may involve columns of the primary table, or columns of any one of the * secondary tables. But it may not involve columns of more than one table. diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/Generated.java b/hibernate-core/src/main/java/org/hibernate/annotations/Generated.java index 2dd3d61f88dc..71b24a4de995 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/Generated.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/Generated.java @@ -31,11 +31,13 @@ *

  • a mapped column has a default value defined in DDL, in which case * {@code @Generated} is used in conjunction with {@link ColumnDefault}, *
  • a {@linkplain #sql() SQL expression} is used to compute the value of - * a mapped column, or - *
  • when a custom SQL {@link SQLInsert insert} or {@link SQLUpdate update} + * a mapped column, + *
  • a custom SQL {@link SQLInsert insert} or {@link SQLUpdate update} * statement specified by an entity assigns a value to the annotated - * property of the entity, or {@linkplain #writable() transforms} the - * value currently assigned to the annotated property. + * property of the entity, or {@linkplain #writable transforms} the + * value currently assigned to the annotated property, or + *
  • there is no mapped column, and the value of the field is determined + * by evaluating a SQL {@link Formula}. * *

    * On the other hand: