Skip to content

Commit f4adfaf

Browse files
Calculate entity property at INSERT or UPDATE time
1 parent ec35b75 commit f4adfaf

File tree

1 file changed

+1
-1
lines changed
  • HibernateSpringBootCalculatePropertyGenerated

1 file changed

+1
-1
lines changed

HibernateSpringBootCalculatePropertyGenerated/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**Key points:**\
66
- annotate the entity persistent field that corresponds to the property that should be calculated with `@Generated(value = GenerationTime.ALWAYS)` or `@Generated(value = GenerationTime.INSERT)`\
77
- annotate the same field with `@Column(insertable = false, updatable = false)`\
8-
- if the database schema is generated via JPA annotations (not recommended) then use `columnDefinition` element of `@Column` to specify the formula/
8+
- if the database schema is generated via JPA annotations (not recommended) then use `columnDefinition` element of `@Column` to specify the formula\
99
- if the database schema is not generated via JPA annotations (recommended way) then add the formula as part of schema in `CREATE TABLE`
1010

1111
**Note:** In production, you should not rely on `columnDefinition`. You should disable `hibernate.ddl-auto` (by omitting it) or set it to `validate`, and add the SQL query expression in `CREATE TABLE` (in this application, check the `discount` column in `CREATE TABLE`, file `schema-sql.sql`). Nevertheless, not even `schema-sql.sql` is ok in production. The best way is to rely on Flyway or Liquibase.

0 commit comments

Comments
 (0)