-->
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: sesionFactory per user schema or command set search_path
PostPosted: Tue Sep 12, 2006 4:19 pm 
Newbie

Joined: Mon Sep 11, 2006 6:41 pm
Posts: 3
I have one webapp with 100 customers. One schema for each customer.
What can i do?
One jndi/dataSorce + sessionFactory for each customer.
Or
execute:

session.connection().prepareStatement("set search_path ="+ myschema).execute();

for each session
????


Hibernate version: 3

Name and version of the database you are using:PostGreSql 8.0


Top
 Profile  
 
 Post subject: Re: sesionFactory per user schema or command set search_path
PostPosted: Fri Sep 15, 2006 12:18 pm 
Newbie

Joined: Mon Sep 11, 2006 6:41 pm
Posts: 3
Somenone knows the best way for this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 2:58 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Every schema is identical, I assume? We have done the set search_path thing you are mentioning, and it has worked very well for us. We wrapped the Hibernate Session and every call to beginTransaction explicity sets the search_path on the connection. (The first real problem we've hit with this is now that we are trying to cluster the db, the clustering technology we are using doesn't seem to handle the search_path correctly.)

Anyway, I'm telling you this so you know that this approach has been done, and can work. Having said that, I'll also say that this is a temporary solution in our case until we can get the schemas combined into a single schema. I'm not sure why you would ever actually want multiple identical schemas. We did it as a short-term solution to handle some legacy issues.

I personally didn't want to go the other route because of the extra memory use caused by having many session factories.

Good luck.

_________________
nathan


Top
 Profile  
 
 Post subject: Re: sesionFactory per user schema or command set search_path
PostPosted: Sat Sep 16, 2006 8:48 pm 
Newbie

Joined: Mon Sep 11, 2006 6:41 pm
Posts: 3
Yes. Every schema is identical.

How do you will combine multiple schemas into a simgle schema?

You will put a WHERE to every HQL? (or SQL)


Top
 Profile  
 
 Post subject: Re: sesionFactory per user schema or command set search_path
PostPosted: Sun Sep 17, 2006 8:08 pm 
Newbie

Joined: Wed Oct 05, 2005 3:36 am
Posts: 15
Assuming that you are using surrogate keys throughout your DB.

leonir wrote:
Yes. Every schema is identical.
How do you will combine multiple schemas into a simgle schema?


You will need to write a utility to do the data migration so that no two records in the same table have the same primary key which is probably an issue because your main hibernate_sequence will currently exist in each of the schemas.

Once you have that you will need to examine your unique constraints.
Basically any unique constraint that encompasses a foreign key to another tables primary key shouldn't cause an issue because your utility has already fixed all the primary keys.

For the remaining unique constraints you will either need to decide if you can live without them or add a new "schema_id" field.


leonir wrote:
You will put a WHERE to every HQL? (or SQL)


A significant number of HQL/SQL's wouldn't need to be changed.
The reason for this is that if you reference a record in one table (by its primary id) and then as part of that query you join to a bunch of other tables the joined records must have originally come from the same schema.

So the only time you would need to add extra where clause is in SQL's where you don't reference a primary (surrogate) key.

However I am guessing that the scope of this will be limited to a few top level tables (probably the same ones you needed to add the extra schema_id fields too).


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.