Thank you! But I tried 2 ways to change the properties.
The content in /fischer_test.hibernate.cfg.xml is the same!
1st WAY:Code:
protected static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
SessionFactory sf = null;
System.out.println("DBHandler.url " + DBHandler.url);
Configuration cfg = new Configuration();
if (DBHandler.url.equals("jdbc:mysql://10.100.1.116/fischer_test")){
cfg.configure("/fischer_test.hibernate.cfg.xml");
System.out.println("conf");
cfg.buildSettings();
}
else {
cfg.configure();
}
return cfg.buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
2nd WAY:Code:
protected static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
SessionFactory sf = null;
System.out.println("DBHandler.url " + DBHandler.url);
Configuration cfg = new Configuration();
if (DBHandler.url.equals("jdbc:mysql://10.100.1.116/fischer_test")){
System.setProperty("hibernate.connection.password", "sadrach");
System.setProperty("hibernate.connection.username", "sadrach");
System.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
System.setProperty("hibernate.connection.url", "jdbc:mysql://10.100.1.116/fischer_test");
System.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
System.setProperty("hibernate.current_session_context_class", "thread");
System.setProperty("hibernate.bytecode.use_reflection_optimizer", "false");
cfg.setProperties(System.getProperties());
System.out.println("conf");
cfg.buildSettings();
}
else {
cfg.configure();
}
return cfg.buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
BUT NOTHING WORKS! ANY IDEA?