I am adding a JPA application to a complex system of many existing applications (written in MS Access, Delphi, Perl, C#, PHP, etc.). The underlying MS-SQL database uses database triggers to write a copy of any altered database entry in a history database table, adding SYSTEM_USER
and GETDATE()
.
Since my new JPA application uses connection pooling - all alterations on database tables will always be made by our technical user (user: "Java") and all the history database table entries of the JPA application will always have "Java" as SYSTEM_USER.
How to let automatically create entries in the history tables - without dropping the existing triggers?
I thought about:
- telling the existing triggers to not to start, whenever the user "Java" modifies tables and creating the history database table entries on my own. Therefore I had to create many new entity classes for each of my history database tables. Not really convienient.
- disabling connection pooling and creating a seperate connection for each modification - using the actual user to connect to the database. But this would have performance drawbacks. And I don't know how to disable connection pooling.
- using a temporary table to always store the current user - and the database trigger should use that stored user when creating the entry in the history database table
- manually changing the user in the history database table after the manipulation.