gdphh wrote:
Hi!
Due to various historical reasons, we have a database schema where table names change every quarter. For example, a person table changes from
Person_2006q1 to Person_2006q2 and so on. My question is, what is the best way to insert/update into these tables without having to regenerate our mappings every quarter? Also, we may need to write to a different quarter based on timestamps on some data being received. Obviously, a static mapping going to table Person_2006q1 will be obsolete by the second quarter. Is there a way to programmatically change the name of the destination table to which data is being written to. I checked through the FAQs but could not find something that was comparable.
Version of Hibernate being used: 3.1
I greatly appreciate your response.
thanks,
gd
Perhaps this might be help - instead of updating the schema from the Hibernate-java code(I am not sure whether this is possible or not - and even it was possible how do one implement that in the java code), one can do this:
write a small program(simple, using java.lang.String and IO api), that parses the mapping file(you may use a Parser as well) and replace the relevant part for reflecting the change in quarter...
for e.g
Person_2006q1 to Person_2006q2
You need to replace "q1" with "q2" -
and you need to run the program on all the relevant mapping files with each quarter change....this little string-manipulation program may be modified so that process of updation is automated.....(sth equivalent) to a database trigger functionality..
Also there is one possibility--however I have not used it:
The Configuration class has this method:
generateSchemaUpdateScript(Dialect dialect, DatabaseMetadata databaseMetadata)
I feel if you were to use that method, then you need to disable the PL/SQL code(I am assuming that in your existing application it is done in this manner) that creates the tables automatically reflecting the updated quarter...