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.  [ 1 post ] 
Author Message
 Post subject: Change config after new Configuration().configure()
PostPosted: Fri Mar 18, 2005 12:02 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Hello,

I am trying to change the default configuration(in hibernate.cfg.xml) after calling configure(). The parameters get set, but they don't have any effect when the SessionFactory is build.

Code
Code:
      if(cfg == null){
         cfg = new Configuration().configure();
         
         // Check if there are database connections settings defined in
         // the preference node
            cfg.setProperty("hibernate.connection.driver_class",
               Settings.s.get(Settings.DATABASE_DRIVER,
                  cfg.getProperty("hibernate.connection.driver_class")
               )
         );
         cfg.setProperty("hibernate.connection.url",
                    Settings.s.get(Settings.DATABASE_URL,
                  cfg.getProperty("hibernate.connection.url")
               )
         );
         cfg.setProperty("hibernate.connection.username",
                    Settings.s.get(Settings.DATABASE_USERNAME,
                  cfg.getProperty("hibernate.connection.username")
               )
         );
         cfg.setProperty("hibernate.connection.password",
                    Settings.s.get(Settings.DATABASE_PASSWORD,
                  cfg.getProperty("hibernate.connection.password")
               )
         );
         cfg.setProperty("show_sql",
               userPrefs.get("show_sql",
                  cfg.getProperty("show_sql")
               )
         );
         cfg.setProperty("dialect",
                    Settings.s.get(Settings.DATABASE_DIALECT,
                  cfg.getProperty("dialect")
               )
         );
         log.debug("Registry: " + Settings.s.get(Settings.DATABASE_DRIVER,
      
// Prints correct values            cfg.getProperty("hibernate.connection.driver_class")
               ));
          log.debug("Starting with [database.url]: " + cfg.getProperty("hibernate.connection.url"));
          log.debug("Starting with [database.driver_class]: " + cfg.getProperty("hibernate.connection.driver_class"));
          log.debug("Starting with [database.username]: " + cfg.getProperty("hibernate.connection.username"));
          log.debug("Starting with [database.password]: " + cfg.getProperty("hibernate.connection.password"));
          log.debug("Starting with [database.dialect]: " + cfg.getProperty("dialect"));
         
      }

// Not configured with values from registry but with settings from default config file
SessionFactory sf = cfg.buildSessionFactory();


Question
Is it possible to first create a default config from a hibernate.cfg.xml and then change it settings?

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.