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: Connection.setCatalog("cat_name") Not persisting p
PostPosted: Tue Jul 31, 2007 12:12 pm 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
OS: Win2k3
JVM: 1.5.0_11-b03
Hibernate: 3.2.4sp1
JConnector: 5.0.4
Database: MySQL 5.0.36 Enterprise

I have a database model which uses a sharded schema. This means that I have a database per account model with multiple databases residing on a physical instance of MySQL. This model is used to acheive scalability in that I have multiple physical machines all running a subset of the accounts to form a complete dataset. Horizontal Scalability...

I have a SessionFactory for each physical database server. The initial connection is made with no default catalog selected:

jdbc:mysq://192.168.0.1/

In the code which returns my hibernate Session objects I always call the following before returning the session:

Session.connection().setCatalog("account_db")

where "account_db" is the actual account which should be used for all hibernate queries. This seems to work 98% of the time, but every once in a while it seems like hibernate will modify the setting and go back to "no database selected" state.

I am using a c3p0 connection pool.

Anyone have any idea what might be causing the issue? Is this something that isn't good practice with Hibernate because of certain underlying functionality? It seems like the right solution... because the other option is to have a SessionFactory per account which would mean i have hundreds or thousands of SessionFactory objects all with their own connection pools and physical connections to the DB.

Any insight is greatly appreciated.
Thanks,
Geoff


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 8:21 am 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
anyone from the Hibernate team care to help me out here?

thanks,
Geoff


Top
 Profile  
 
 Post subject: Opening Session
PostPosted: Wed Aug 01, 2007 5:57 pm 
Newbie

Joined: Fri Apr 07, 2006 11:29 am
Posts: 17
Perhaps this is happening 2% of the time because the session has somehow been closed? Then the new session would not have the database set.

Quote:
In the code which returns my hibernate Session objects I always call the following before returning the session:

How are you opening the sessions, and handling the setCatalog?

Are you using any other frameworks, like Spring?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 11:23 am 
Beginner
Beginner

Joined: Fri Apr 22, 2005 5:58 pm
Posts: 26
I return all my Session objects through a HibernateUtil which has private access to the SessionFactory to ensure no external access.

Before the Session object is returned it has the Session.connection().setCatalog() called to point to the correct schema.

I have even resorted to calling setCatalog() before starting new Transactions on a session... aside for more traffic to the DB it doesn't appear to have changed anything.

Thanks,
Geoff


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.