Dialect resolution: Cannot set a custom dialect resolver programatically or using hibernate.cfg.xml

Description

Starting with version 3.3, Hibernate introduced an extremely useful dialect resolution feature (http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#portability-dialectresolver). The problem is with the configuration of a custom dialect resolver:

  • Setting the property Environment.DIALECT_RESOLVERS in the Configuration of a SessionFactory doesn't work, because DialectFactory only reads from Environment.getProperties(), which is only the global properties (system properties plus the hibernate.properties file).

  • Setting a system property programatically is not safe, because the Environment class caches the system properties in a static constant, so if it's loaded before the code that sets the system property, the property will not be picked up.

  • The registerDialectResolver() method on DialectFactory is not public.

Ideally, it should be possible to configure a custom dialect resolver by setting the property Environment.DIALECT_RESOLVERS on a Configuration object, just as one would configure an explicit dialect. Alternatively, I think an acceptable "quick fix" would be to expose the registerDialectResolver() method on DialectFactory.

Environment

None

Activity

Show:
Steve Ebersole
June 11, 2010, 6:55 PM

I agree with what you are saying, however there is an issue of scope. As you pointed out, there is a lot of static-ness going on in Hibernate configuration. The DialectResolvers registered with the DialectFactory are static as well. Unfortunately this is just the way this stuff is designed at the moment. There is a plan to change it. Please see the design area of the wiki ( http://community.jboss.org/en/hibernate/dev/design ) for discussions of this. http://community.jboss.org/docs/DOC-15371 is the discussion that most directly bears on this subject; its just a brief synopsis at this time though.

Steve Ebersole
March 5, 2011, 12:01 AM

This is fixed by the introduction of services and migration of dialect resoltion to be a service

Laird Nelson
July 14, 2011, 12:25 AM

Do you know if in version 3.5.0 you are supposed to be able to set {hibernate.dialect_resolvers} in a {META-INF/persistence.xml} {<properties>} stanza? Or does that get translated into one of the ways that doesn't work?

Laird Nelson
July 14, 2011, 9:23 PM

For those following along: that gets translated into one of the ways that doesn't work.

Assignee

Steve Ebersole

Reporter

Nikita D

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure