write expression must contain exactly one JDBC-style '?' placeholder.
read expression may not contain JDBC-style placeholders.
For example:
@Column(name="credit_card_num")
@ColumnTransformer(read="decrypt(credit_card_num)"
write="encrypt(?)")
String creditCardNumber;
A column transformer write expression transforms the value of a persistent
attribute of an entity as it is being written to the database.
read expression to undo the effect of this
transformation, then we're entitled to consider the in-memory state of the Java
entity instance as synchronized with the database after a SQL insert or
update is executed.
read expression, or if the
read expression does not exactly undo the effect of the transformation, the
in-memory state of the Java entity instance should be considered unsynchronized
with the database after every SQL insert or update is executed.
In the second scenario, we may ask Hibernate to resynchronize the in-memory state
with the database after each insert or update by annotating the
persistent attribute @Generated(event={INSERT,UPDATE}, writable=true).
This results in a SQL select after every insert or update.
ColumnTransformers
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public String | |
| public String |
| forColumn | back to summary |
|---|---|
| public String forColumn() The name of the mapped column, if a persistent attribute maps to multiple columns. Optional if a persistent attribute is mapped to a single column | |
| read | back to summary |
|---|---|
| public String read() A custom SQL expression used to read from the column. | |
| write | back to summary |
|---|---|
| public String write() A custom SQL expression used to write to the column. The expression must contain exactly one JDBC-style '?' placeholder. | |