0

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:

  1. 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.
  2. 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.
  3. 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
  4. manually changing the user in the history database table after the manipulation.
slartidan
  • 20,403
  • 15
  • 83
  • 131

1 Answers1

0

1 - If you are using EclipseLink, you potentially could use its history support. See, http://wiki.eclipse.org/EclipseLink/Examples/JPA/History

2 - In EclipseLink you can provide the user/password properties to createEntityManager() to use a non-pooled connection. See, http://wiki.eclipse.org/EclipseLink/Examples/JPA/Auditing#Provide_each_application_user_with_a_database_user_id

4 - You could use JPA or EclipseLink events for this.

James
  • 17,965
  • 11
  • 91
  • 146