-->
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.  [ 4 posts ] 
Author Message
 Post subject: One Class, Many Tables: variable table name
PostPosted: Tue Nov 15, 2005 3:39 pm 
Newbie

Joined: Tue Nov 15, 2005 10:38 am
Posts: 4
Hibernate version: 3.0
Using Oracle 10g:

I'm new to Hibernate, and I like what I see so far, but I need some help with an odd data model.

This data model (inherited, non-negotiable) contains, among other tables, a virtually unbounded number of tables with the exact same structure and slightly different names. For example:
    my_data_1
    my_data_2
    ..
    my_data_n

all have the exact same structure (in the actual database the names are not sequential, but you get the idea). The theoretical upper limit of n is roughly a billion. I'd like to load, update, save and delete objects for these tables using Hibernate, but I'd obviously rather not create a separate object and mapping file for each table, especially since part of the application creates these tables dynamically. The easiest solution (imho) would be for me to be able to specify the table name when I perform the load(), save(), update(), etc. operation, but I know I can't do that.

My alternative approach would be to create a template hbm.xml file and plug in the table name and create a new SessionFactory whenever I want to work with one of these tables. There are some obvious drawbacks to this approach, but I think it would work under very restrictive circumstances.

My question is, is there a better way to do something like this that I've missed in all of the Hibernate docs I've looked through (other than re-working the data model)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 5:01 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You're absolutely right! Once the SessionFactory is alive, there's no way of changing the mapping anymore.

There's one thing to note: The creation of the session factory can take some seconds. If you have to recreate the session factory very often this could be a problem.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 9:33 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
I hope your "non-negotiable" data model doesn't say anything about adding new things to it? :) You can write your own store procedure to handle the ever changing table names, and map the SP as custom SQL statements.

See 17.4. Custom SQL for create, update and delete for details.

jd


Top
 Profile  
 
 Post subject: One Class, Many Tables: variable table name
PostPosted: Wed Nov 16, 2005 9:32 am 
Newbie

Joined: Tue Nov 15, 2005 10:38 am
Posts: 4
Thanks, jd001982. While I was hoping to avoid writing SQL for these tables, I think this could be a workable fallback plan.

Although, if I need to set each value in the stored procedure call (e.g. with .setString(), .setInteger(), etc), it might be difficult to sell the use of Hibernate in this case over JDBC to my colleagues who are already familiar with JDBC. One aspect of these tables is that they are relatively wide (128 columns), so you can see how having to set each column value from the object is not attractive.

It's not clear to me whether I would need to ".setXXX" each value, but that's what it looks like from the doc. I'm going to search around for some examples that use the stored procedure approach.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.