Annotation Type SQLUpdate
@Target({TYPE,FIELD,METHOD})@Retention(RUNTIME)@Repeatable(SQLUpdates.class)public @interfaceSQLUpdate
Specifies a custom SQL DML statement to be used in place of the default SQL generated by Hibernate when an entity or collection row is updated in the database.The givenSQL statement must have exactly the number of JDBC
?parameters that Hibernate expects, that is, one for each column mapped by the entity, in the exact order Hibernate expects. In particular, theprimary key columns come last unless the entity isversioned, in which case there must be a second JDBC parameter for the version column, which comes after the primary key.If a column shouldnot be written as part of the update statement, and has no corresponding JDBC parameter in the custom SQL, it must be mapped using
updatable=false.A custom SQL update statement might assign a value to a mapped column as it is written. In this case, the corresponding property of the entity remains unassigned after the update is executed unless
@Generated(event=UPDATE)is specified, forcing Hibernate to reread the state of the entity after each update.Similarly, a custom update statement might transform a mapped column value as it is written. In this case, the state of the entity held in memory loses synchronization with the database after the update is executed unless
@Generated(event=UPDATE, writable=true)is specified, again forcing Hibernate to reread the state of the entity after each update.If an entity hassecondary tables, it may have a
@SQLUpdateannotation for each secondary table. Thetable()member must specify the name of the secondary table.
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleancallableIs the statement callable (aka aCallableStatement)?ResultCheckStylecheckDeprecated.useverify()with anExpectationclassStringtableThe name of the table affected by the update statement.Class<? extendsExpectation>verifyAnExpectationclass used to verify that the operation was successful.
Element Detail
sql
String sql
Procedure name or SQLUPDATEstatement.
callable
boolean callable
Is the statement callable (aka aCallableStatement)?- Default:
- false
verify
Class<? extendsExpectation> verify
AnExpectationclass used to verify that the operation was successful.- Default:
- org.hibernate.jdbc.Expectation.class
check
@Deprecated(since="6.5")ResultCheckStyle check
Deprecated.useverify()with anExpectationclassAResultCheckStyleused to verify that the operation was successful.- Default:
- org.hibernate.annotations.ResultCheckStyle.NONE
table
String table
The name of the table affected by the update statement. Required when the statement affects asecondary table of an entity. Not required for collections nor when the insert statement affects the primary table of an entity.- Returns:
- the name of the secondary table
- Since:
- 6.2
- Default:
- ""