Package org.hibernate.annotations
Annotation Type ColumnTransformer
-
@Target({FIELD,METHOD}) @Retention(RUNTIME) @Repeatable(ColumnTransformers.class) public @interface ColumnTransformer
Specifies custom SQL expressions used to read and write to the column mapped by the annotated persistent attribute in all generated SQL involving the annotated persistent attribute.- A
write()expression must contain exactly one JDBC-style '?' placeholder. - A
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.- If there is a matching
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 SQLinsertorupdateis executed. - On the other hand, if there's no matching
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 SQLinsertorupdateis executed.
In the second scenario, we may ask Hibernate to resynchronize the in-memory state with the database after each
insertorupdateby annotating the persistent attribute@Generated(event={INSERT,UPDATE}, writable=true). This results in a SQLselectafter everyinsertorupdate.- See Also:
ColumnTransformers
- A
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description StringforColumnThe name of the mapped column, if a persistent attribute maps to multiple columns.StringreadA custom SQL expression used to read from the column.StringwriteA custom SQL expression used to write to the column.
-
-
-
Element Detail
-
forColumn
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- Default:
- ""
-
-
-
read
String read
A custom SQL expression used to read from the column.- Default:
- ""
-
-
-
write
String write
A custom SQL expression used to write to the column. The expression must contain exactly one JDBC-style '?' placeholder.- Default:
- ""
-
-