I have a Java application that connects to a Postgres DB using EclipseLink.
My problem is that database triggers are triggered before the Java/EclipseLink transaction is completed causing the data to be incorrect.
There is a trigger to update a
order_logstable every time there is an
setter()method is called on an
OrderEntityinstance, the database logs indicate that the trigger is run for every two
setter()method calls within the same transaction. This results in the
order_logstable having multiple rows for only one update.
My question is that is there a way to force/ensure that the trigger is triggered only at the end of a transaction. I had a look at this page but deferring looks like it’s just for foreign keys. My methods are wrapped with the
The trigger was created using:
create trigger my_insert_update_trigger after insert or update on public.my_table for each row execute procedure my_insert_update_trigger_function();
I ended up having to add this line:
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />