-->
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.  [ 8 posts ] 
Author Message
 Post subject: modification of the hibernate mapping at runtime?
PostPosted: Thu Aug 04, 2005 7:43 pm 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
Does anyone know if it is possible to modify the hibernate mapping during runtime?

I am using Hibernate 3, and here is a very brief rundown of what I want to accomplish.

I have a system which has a set of 4 tables. Each client on the system has their own table set which are all suffixed with their client ID (tbl_myTable_000000 or tbl_myTable_111111).

My Java app is going to have a Thread per Client model. Where each thread will be accessing its tbl_myTable_[client id] tables for processing. There is no reason I need to have a set of Java classes for each client, because they are all going to be the same. I know I will need a SessionFactory per Thread, but what I would like to do is have it load the same base configuration files, then modify them at runtime to map to the correct _[client id] tables.

Is the modification/reload of the configuration possible at runtime?

Thanks in advance!
Geoff


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 10:48 am 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 10:52 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Just want to say why do you create different tables and why don t you have a clientid on your tables two know to which client the record belong.

Maybe runtime manipulation work (you can try it) but it does not seem to me to be a good design choice

Seb


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 11:09 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 10:34 am
Posts: 38
Additionally you can use a session filter to restrict all queries to one client id.

See http://www.hibernate.org/hib_docs/v3/reference/en/html/filters.html#objectstate-filters

scesbron wrote:
Just want to say why do you create different tables and why don t you have a clientid on your tables two know to which client the record belong.

Maybe runtime manipulation work (you can try it) but it does not seem to me to be a good design choice

Seb


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 11:50 am 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
I have been designing databases for a very long time... and have decided that this is the way to go.

I have a couple of good reasons why I have decided to create client specific tables as opposed to using key relationships...

1) The tables will be re-indexed, truncated, etc... things that would temporarily lock a table.

2) Each client will have millions of records. I would like to keep it as simple as possible to move a client to a new physical piece of hardware if they ever beging using too much processing power.

3) There are going to be many columns that aren't shared between clients... but these will not be "known" by my Java application running Hibernate... so the model still works.

I am very familiar with database normalization... so that isn't the point here. I am just wondering about runtime modification of the mapping files...

Thanks,
Geoff


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 12:16 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Ok, this is just a question.

If the number of client is known at compile time you can also create a bunch of hbm files from a core one with a ant script if runtime modification isn't possible (I don't know if it is)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 12:53 pm 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
I would prefer to not have to rebuild the code each time I add a new client. The system will peridocally check which clients exist, and automatically configure itself to begin or terminate servicing those clients in near real time. I am digging through the many layers of hibernate right now looking for something that looks like it would allow me to modify mapping documents at runtime... no luck so far :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 1:27 pm 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
Ok.. well I have figured it out... it took a bit of hacking, but I got it.


/*
* *************************************************
* *************************************************
*/
import org.hibernate.mapping.*;
import org.hibernate.cfg.*;
import org.hibernate.*;

...
...
...

Configuration configuration = new Configuration();
Iterator i = configuration.getTableMappings();

while(i.hasNext()){
Table table = (Table)i.next();
table.setName(table.getName() + "_000000");
}

SessionFactory factory = configuration.buildSessionFactory();
Session sess = factory.openSession();

/*
* *************************************************
* *************************************************
*/


That should do it... now the SessionFactory will automatically be pointing to the _0000000 tables for the application. Probably what I will do is load the table set into a map and update them based on the need... seeing as there are some shared tables in my schema that don't have the _clientID.

Thanks for everyones help.

geoff


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