exoplatform/core — pull request #4 by mposolda (2012-08-15 13:26:52+00:00)
Title: Stable/2.4.x - Hibernate4 support

Currently HibernateServiceImpl is using some Hibernate internal API, which is not compatible with Hibernate4. Using of this internal API is not needed even for Hibernate 3.3. So I tried to remove all usage of this stuff and make HibernateServiceImpl compatible with both Hibernate3 and Hibernate4. Details below:

- In the constructor of HibernateServiceImpl, there is some code for injection of ExoCacheProvider as Hibernate CacheProvider implementation. This code is not compatible with Hibernate4 and does not compile as CacheProvider API has been removed in Hibernate4. But thing is, that this injection is obsolete and it doesn't work in Hibernate 3.3 as well!
The reason is that Hibernate method SettingsFactory.createCacheProvider(Properties properties), which is overriden in eXo class HibernateSettingsFactory, has been removed even before Hibernate 3.3 and this method is no longer available in Hibernate 3.3. So this method is not invoked during Hibernate SessionFactory initialization. So Hibernate ignores this ExoCacheProvider and it uses CacheProvider from hibernate configuration. In other words, there is no impact in removing this code as it doesn't work in Hibernate 3.3 anyway.

- Later in the constructor of HibernateServiceImpl, there is some code for detecting of database dialect, which is also not compatible with Hibernate4. But thing is, that this code is not needed for Hibernate3 as well, because from version 3.3, this dialect autodetection feature is provided by Hibernate itself. See http://docs.jboss.org/hibernate/core/3.5/reference/en-US/html/portability.html#portability-dialectresolver . Hibernate algorithm used for autodetection is quite same like the one used by HibernateServiceImpl (it's based on DatabaseMetadata object obtained from DB connection). So to make compatible with Hibernate4, I removed this detection code.

- In HibernateServiceImpl.getSessionFactory() there is call to execution of SchemaUpdate. This is also not needed if user configures property "hibernate.hbm2ddl.auto" in Hibernate configuration. I left it here for backwards compatibility, but with Hibernate3, there is need to have Dialect available in Hibernate configuration object (which I removed in previous point). So I added method "updateDialectInConfiguration", which is able to obtain detected dialect from SessionFactory object and add it back to Configuration object. I used reflection to be runtime-compatible with both Hibernate3 and Hibernate4.

With these changes, HibernateServiceImpl is working for both Hibernate3 and Hibernate4.

I am adding 2 commits - First commit is for changes in HibernateServiceImpl for make it Hibernate4 comaptible. This is needed for GateIn to have Hibernate4 support.
Second commit is for update dependency to Hibernate 4.1.2.Final and remove some obsolete Hibernate3 stuff (mostly related to CacheProvider API). This is not necessarily needed for GateIn, it's needed only in case that you want to upgreade Hibernate version in exo.core