Projects:Register SQL Functions/Specs
Goal
The goal of this project is to provide a new mechanism to register SQL functions to be used in HQL, and deprecate the current method intended for this purpose, which is no longer supported in newer Hibernate versions.
The main objective is to provide this new mechanism before the introduction of the Hibernate upgrade, in order to minimize the impact of all the changes involved in that project.
Current Status
The current way of registering SQL functions is done by calling the OBDal.registerSQLFunction(String, SQLFunction) method. This method assumes that it is possible to register SQL functions in Hibernate at runtime. This is no longer possible in newer Hibernate versions where it is only possible to register SQL functions when Hibernate is being initialized.
See here and here for additional information.
New Registering Infrastructure
Currently, there exists different ways to register SQL functions in Hibernate:
- Create a custom Dialect and register the SQL functions on the constructor.
- Get the Configuration object when the application starts and directly add the SQL functions into the configuration.
- Use a MetadataBuilderInitializer class.
The solution to be implemented will be based on the second approach, i.e., by taking the Hibernate configuration and register the SQL functions directly on it. This is one of the recommended approaches in the Hibernate 5.3.0 User Guide and also very feasible to implement in Openbravo.
Therefore, to implement this solution the SessionFactoryController will provide a new method that will return the list of SQL functions to be registered with the Configuration class provided by Hibernate. This new method will be overridden by those classes extending the SessionFactoryController.
In particular, the DalSessionFactoryController will override this method, retrieving the SQL functions to be registered using CDI. Thus, it will provide the ability for registering the core SQL functions but it will also allow adding new ones with external modules.