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

Activity

Show:
Brett Meyer
April 7, 2014, 5:47 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Christoph Strebin
April 12, 2014, 5:01 PM

This bug is still valid for hibernate-core-4.3.5.Final.jar: Method Configuration.buildSessionFactory(ServiceRegistry) calls copy.putAll(properties) and this.properties may include defaults, since they are publicly settable in setProperties. So the SessionFactoryImpl may still get incomplete properties.

Brett Meyer
April 14, 2014, 12:40 PM

Thanks for the response

Steve Ebersole
September 26, 2015, 12:59 PM

Rejecting this. 4.x (and earlier) are no longer maintained. And in 5.0 I moved away from Properties to a Map for holding config setting values. Hibernate always operated that way anyway because it allowed non-String values.

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