This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Get the current updating row, to be inserted into another table using trigger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get the current updating row, to be inserted into another table using trigger" Watch "Get the current updating row, to be inserted into another table using trigger" New topic
Author

Get the current updating row, to be inserted into another table using trigger

Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 201
Hello all,


I have two tables, entity and entity_historical_data. I want to maintain the historical data of each entity that was updated. So, if an entity is updated 5 times, I will have five records in the entity_historical_data for the corresponding entity ID. Also, the columns in the entity and entity_historical_data are more or less the same.

I am using Hibernate for the application and my current implementation involves manually inserting in the entity_historical_data table using hibernate before an entity with a given id is updated.

I'd like to do this using triggers, such that before update, existing record (row) which is gonna updated (old) will be added in the entity_historical_data table and then the update will be performed.

So, I will need all the data of the row which is going to be updated and will insert that data into another table using trigger.

Can someone help me with this ?

Deepak Pant
Ranch Hand

Joined: Feb 13, 2004
Posts: 443
Assuming that you are using Oracle database, you will need at least following types of Triggers:

1. CREATE OR REPLACE TRIGGER <<your trigger name>> AFTER DELETE ON <<your table name>> FOR EACH ROW
- access the current column values of the row being deleted as :OLD.<<column name>>

2. CREATE OR REPLACE TRIGGER <<your trigger name>> AFTER UPDATE ON <<your table name>> FOR EACH ROW
- access the old column values of the row being updated as :OLD.<<column name>>
- access the new column values of the row being updated as :NEW.<<column name>>

The syntax/semantics will change based on the database being used.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get the current updating row, to be inserted into another table using trigger