-->
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.  [ 6 posts ] 
Author Message
 Post subject: Dynamicly generated new database?
PostPosted: Fri Nov 18, 2005 1:15 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
Hibernate version: 3.0

Name and version of the database you are using: MySQL 4.1



Hi,

I am considering to use Hibernate for our J2EE application but have one question. Our application dynamically generates databases during runtime, which need to be accesible without a restart. Does hibernate allow for this, and does it thus allow dynamic updates of the hibernate.cfg.xml file?

Thank you,

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 1:40 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
Yes, you can reload the configuration with new objects. You don't need to use the hibernate.cfg.xml, there are classes in the framework to load new mappings.
It's possible to be done. But I haven't done it b4.
But it may require some testing, if this process of table change happens too often, you may get some performance problems. Using or not using hibernate.

_________________
Alexandre Torres
--------------------


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 1:57 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
atorres wrote:
But it may require some testing, if this process of table change happens too often, you may get some performance problems. Using or not using hibernate.


Max a couple of times a week, so I don't think performance should be too much of a problem, right?

You mention "process of table change". What do you mean by this as I'm inquiring about database creation, not table creation.

Thank you,

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 2:03 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
Sorry, you are just changing the database and not the table schema?
If it's a distinct vendor (like Mysql to Postgres) you have to change the translator. If it's just connection, you can build the session passing connections as parameter.
And even if you have distinct tables and databases it's still possible to do, but may require some extra work. You may have to work with different classes to different database structure.

_________________
Alexandre Torres
--------------------


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 5:33 pm 
Newbie

Joined: Mon Aug 15, 2005 3:57 pm
Posts: 13
I had a similiar issue in my swing app where the user had to select a particular database/schemata/catalog (different databases use different terminology here) within mySQL.

I used a helper class that dynamically assigns the connection url, passing it the name of the database to use.


Relevant code:

//HibernateHelper Constructor
public HibernateHelper(String dbName)
{
String connectURL = "jdbc:mysql://localhost/" + dbName;
sessionFactory= new Configuration()
.setProperty("hibernate.connection.url", connectURL)
.configure()
.buildSessionFactory();
}



//In main app

HibernateHelper hh = new HibernateHelper("name_of_database_to_use");
Transaction trans = hh.getSession().beginTransaction();

// do stuff here,

trans.committ();

Is it possible, or wise, to use multiple SessionFactories within your app. I don't know, but I hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 5:58 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
spovilaitis,

Thanks! Very usefull.

Regards,
Joost

_________________
Joost Schouten
JS Portal


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