Package org.hibernate.annotations
Annotation Type Formula
-
@Target({METHOD,FIELD}) @Retention(RUNTIME) public @interface Formula
Specifies an expression written in native SQL that is used to read the value of an attribute instead of storing the value in aColumn
. AFormula
mapping defines a "derived" attribute, whose state is determined from other columns and functions when an entity is read from the database.// perform calculations using SQL operators @Formula("sub_total + (sub_total * tax)") long getTotalCost() { ... }
// call native SQL functions @Formula("upper(substring(middle_name, 1))") Character getMiddleInitial() { ... }
ColumnTransformer
is an alternative, allowing the use of native SQL to read and write values.// it might be better to use @ColumnTransformer in this case @Formula("decrypt(credit_card_num)") String getCreditCardNumber() { ... }
- See Also:
ColumnTransformer
,DiscriminatorFormula
,JoinFormula
-
-
Element Detail
-
value
String value
The formula, written in native SQL.
-
-