The values for some columns are only meant to be inserted and never modified (effectively complex foreign keys but not mapped as such for various reasons). In JPA, this can be modeled via @Column(updatable=false)
.
Is there a way to systematically (not manually) achieve this in jOOQ? I’m aware of the read-only columns, but immutable (insert-only) columns don’t seem to exist. Is that correct?
I know jOOQ is aware of JPA annotations in some contexts and since I do use the generated DAOs most of the time, I guess I could still use the annotation, but I’d prefer not to as I don’t use JPA anywhere else in the project.
2
Answers
Here’s a sample trigger that could ignore updates to the "x" column on a table named "foo"
The trigger by @lance-java is completely invalid for Postgres (it’s Oracle perhaps). Postgres requires a function that returns trigger and a trigger definition invoking that function. However, the approach is appropriate; just replace the new value with the existing one (no reason to even look at the values). See demo.
Note. Older versions of Postgres may require execute procedure … on the trigger definition.