[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2569) Improve cast() HQL function to support user defined function calls

Gergely Papp (JIRA) noreply at atlassian.com
Mon Apr 16 05:46:04 EDT 2007


Improve cast() HQL function to support user defined function calls
------------------------------------------------------------------

                 Key: HHH-2569
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2569
             Project: Hibernate3
          Issue Type: Improvement
          Components: query-hql
    Affects Versions: 3.2.3
         Environment: Hibernate 3.2.3ga
DB2 UDB 8.1-9.0
            Reporter: Gergely Papp
         Attachments: CastFunction.java

The cast() function could enable the HQL language to call user defined functions that are not explicitly defined in the dialect. 

This is quite easy, considering everything is ready for it in the Hibernate framework, except for the problems in the actual SQL rendering of the function. 

Currently the org.hibernate.dialect.function.CastFunction's render() method receives the arguments as a list, where the last argument is always the target type of the cast. For functions undefined in the dialect the arguments are split at commas.

eg. cast (func(a,b) as int) is received as ["func(a", "b)", "int"]

The problem here is that the arguments are checked if their size equals to two. This is the case for pre-defined functions, but not for user functions that have more than 1 parameters. (NB. currently this allows you to call user-defined functions with a single parameter and only fails on multi parameter functions, which could classify this as a bug)

However if the method is modified, to accept arguments lists with more than 2 elements, and we concatenate the arguments before it, this issue could be solved.

This would enhance the HQL a lot, as using user defined functions in several projects is a must, but writing a new dialect for it is not something an average programmer can figure out.

The proposed modification is attached, it has been tested with DB2 and seems to work as expected, I hope it can find it's way  in the release soon as our project depends on this. 

(The best would be to connect to the db and query the user-defined functions from it on startup, and register those in the dialect, but I think that's quite a huge modification.) 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list