big misdesign in org.hibernate.cfg.Configuration breaks delegation Model of java.util.Properties

Description

Configuration object and org.hibernate.cfg.Environment have lots of methods like

addProperties(Properties extraProperties)
setProperties(Properties properties)
buildSessionFactory()
..... (lots of other ones)

which all manipulate java.util.Properties as it was only a Map (calls to putAll methods with properties as argument, calls to entrySet(), etc). This is very wrong, as a java.util.Properties is more than a map. Calling map related method only access the first level of the properties. It does not take into account the default value stored in a delegate Properties.

Example code:

Properties generic = new Properties();
generic.setProperty("hibernate.connection.url","jdbcostgresql://localhost/mydatabase");
generic.setProperty("hibernate.connection.driver_class","org.postgresql.Driver");
generic.setProperty("hibernate.connection.username","defaultUser");
generic.setProperty("hibernate.connection.password","defaultPassword");
Properties specific = new Properties(generic);
specific.setProperty("hibernate.connection.username","user1");
specific.setProperty("hibernate.connection.password","password");
System.out.println(specific.getProperty("hibernate.connection.url")); // printout jdbcostgresql://localhost/mydatabase
Configuration c = new Configuration().configure(urlWithMyMappings).addProperties(specific);

A unit test should be easy to derivate from this example code + existing hibernate unit tests (if those exist)

Now, when you use that configuration, you will notice Hibernate does not see the hibernate.connection.driver_class and hibernate.connection.url properties, poping out exceptions at will, while it's not documented anywhere to not use the form new Properties(defaultProperties).

Solution:

  • Either don't use the map/collection related methods of java.util.Properties, instead use the propertyNames() Enumeration when the content of a Properties object has to be analyzed! (Remove all calls like properties.putAll(), properties.keySet(), properties.entrySet())

  • Either change the Configuration interface to take a Map and not a java.util.Properties as all code in Configuration and related classes consider it a s a simple Map

Environment

Does not matter (Hibernate 3, even cvs has the bug)
java 1.4.2

Assignee

Unassigned

Reporter

dd

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure