These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: programmatically changing destination table
PostPosted: Tue May 23, 2006 12:12 pm 
Newbie

Joined: Tue May 23, 2006 12:02 pm
Posts: 2
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

_________________
gdphh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 4:01 am 
Newbie

Joined: Mon Jun 05, 2006 3:47 am
Posts: 1
Hi all,

I have a similar situation with gdphh. I have tables with dates appended to them during creation. These set of tables are structurally identical except for the table name.

Is there a way to programmatically change the table name specified in the mapping file?

Thanks in advance.

Hibernate Version : 3.0.5


Top
 Profile  
 
 Post subject: Re: programmatically changing destination table
PostPosted: Mon Jun 05, 2006 6:39 am 
Beginner
Beginner

Joined: Wed May 17, 2006 3:38 am
Posts: 45
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...

_________________
===============================
Rate, if it helped


Top
 Profile  
 
 Post subject: Re: programmatically changing destination table
PostPosted: Mon Jun 05, 2006 7:44 am 
Newbie

Joined: Tue May 23, 2006 12:02 pm
Posts: 2
Thanks bibroy for the response. We played with changing the mapping file and such but finally decided to use a stored procedure that does the decision making of deciding which table to update. Folks here felt that making that logic local to the database was better than embedding it in the application.

thanks,
gd

bibroy wrote:
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...

_________________
gdphh


Top
 Profile  
 
 Post subject: Re: programmatically changing destination table
PostPosted: Mon Jun 05, 2006 8:06 am 
Beginner
Beginner

Joined: Wed May 17, 2006 3:38 am
Posts: 45
Well, does that solve your problem.....I thought and mentioned in the posting you must have been using PL/SQL code(stored procedure ) to create new updated tables to reflect your change in quarter.....but how you are handling the updating the mapping file which earlier had the table say, person_q1 mapped and need to change to person_q2....well definitely the stored procedure has no access to hibernate mapping file ?????

_________________
===============================
Rate, if it helped


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.