-->
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: How to map to a dynamic table name?
PostPosted: Wed Jul 28, 2004 6:24 pm 
Newbie

Joined: Tue Oct 28, 2003 6:00 pm
Posts: 14
Can I map the same class to a different table at runtime? For example, can I map class Review to both REVIEW and REVIEW_2002 which have the same table structure depends on some condition?

We have an application which handles employee's annual review data. It has 3 year worth of data, and I am in the process of devising an archiving solution before the query gets too slow. The idea is to move the historical data to its own table, i.e. REVIEW_2000, REVIEW_2001, and REVIEW_2002. I have thought about using inheritance or interface to solve the mapping such as having Review2002 that inherits Review class. However, it requires creating new mapping class and duplicated mapping definition for each year. There must be a better way to handle this problem. Can anyone shed some light?

Thanks,
Barry


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 29, 2004 7:35 pm 
Newbie

Joined: Tue Oct 28, 2003 6:00 pm
Posts: 14
I searched through the forum and found a few other users tried to do a similiar thing, but couldn't find a definite answer or sample code. Here's what I came up after the research,

Code:
      PersistentClass pClass = config.getClassMapping(clazz);
      Table table = pClass.getTable();
      table.setName(newTableName);
      pClass.setTable(table);


It is not working unfortunately. The table name was changed successfully, but the generated SQL still points to the old table name. It there cache somewhere that I need to invlidate/refresh?

Someone in the forum mentioned using custom persister for this requirement. Are there any examples that I can look into?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 29, 2004 7:47 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Did you rebuild your SessionFactory from the modified Configuration?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 30, 2004 3:20 pm 
Newbie

Joined: Tue Oct 28, 2003 6:00 pm
Posts: 14
christian wrote:
Did you rebuild your SessionFactory from the modified Configuration?


No, I didn't. I figured out that all the SQLs are cached once the SessionFactory is built. Anyway, changing the meta model like this will not serve my needs as it will affect other parts of the system. The goal is to change the query on the fly without altering the original mapping or the original mapping should be restored immediately, so other queries/updates to the main table are not affected. It looks like that I will have to go with creating multiple mappings and inherited classes for this requirement unless there's more natural mechanism than updating the mappings through Configuration.

Thanks,
Barry


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 30, 2004 3:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can have two SessionFactory instances.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.