-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to change database schemas?
PostPosted: Tue Dec 14, 2004 12:26 pm 
Newbie

Joined: Tue Dec 14, 2004 12:13 pm
Posts: 1
Hi experts, I'm trying to move my application to Hibernate. Until now, I was using JDBC to persists my POJOs to the database.
I made a couple of test and everything just worked fine.
But I've got this little problem.
Let me explain it.

private PreparedStatement selectAll(Connection aCon) throws SQLException{
StringBuffer text = new StringBuffer();
text.append("Select * from " + this.getSchema() + "jkEmpresa");
text.append(" where activo = 1");
PreparedStatement qSelect = this.getPreparedStatement(aCon, text.toString());
return qSelect;
}

This is a very common select I use in all the table, just a select * from the table.
If you can see, I use a method, "this.getSchema()", which resolves me the database I'm using.
As my application saves data from the front end, in different databases occording to the user configuration, I use that method to solve that for me.
Eg: If i'm in database 1, it'll make:

select * from database1.dbo.jkempresa or
select * from database2.dbo.jkempresa...

Now, the only way see to make Hibernate do this for me, is using different datasources, each one pointing to different databases... am I wrong?? do you have any ideas???
Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 2:56 pm 
Newbie

Joined: Sat Jul 17, 2004 5:13 pm
Posts: 8
Location: Edegem, Belgium
You should create different SessionFactory's.

From the Advanced FAQ in http://www.hibernate.org/117.html:

Quote:
How do I use multiple databases?
You must configure multiple SessionFactory instances.


Regards,

Jos


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 4:34 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
or take a J2EE Server
or take http://c-jdbc.objectweb.org/

HTH
Ernst


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