As is described in this post: https://stackoverflow.com/questions/36700139/hibernate-valuegenerationtype-applied-at-insert-but-not-update-time the generated values by database in timing “ALWAYS” is not working as expected
The method referenceColumnInSql is defined to return true and the method getDatabaseGeneratedReferencedColumnValue returns the value “current_timestamp”
So it is expected that the update statement also include the column and sets it’s value to “current_timestamp” but the column is missing in the update statemet and it is only included in the select statement to get the value from the database, but the value is never changed.
It is necesary to include the column in the update statement.
This is the annotation definition:
This is the implementation class definition:
when I insert the entity in the database, I got these statements:
Which is correct. It references the column "modification_time" (Annotated with the ModificationTime annotation in the entity definition) and set que insert statement using "LOCALTIMESTAMP" as defined in the getDatabaseGeneratedReferencedColumnValue() method.
But when I update the entity I get these statements:
Which is clearly wrong, because it doesn't reference the column in the UPDATE statement (should set "modification_time=LOCALTIMESTAMP") but it query the value to get the "updated generated" value. But the value doesn't change, because the field is missing in the update statement.
I tried to generate a test case for this submission, but i can't make it work. But it seems to me that the information here is very clear and you can check it easily.