[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6719) org.hibernate.sql.Template prefixes all ` and " with the generated HQL alias so not all SQL strings in formulas are generated correctly when we want to use ` in column name/table names

Krasimir Chobantonov (JIRA) noreply at atlassian.com
Mon Oct 10 06:42:22 EDT 2011


org.hibernate.sql.Template prefixes all ` and " with the generated HQL alias so not all SQL strings in formulas are generated correctly when we want to use ` in column name/table names
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: HHH-6719
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6719
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
         Environment: hibernate 3.3.2.GA and up
            Reporter: Krasimir Chobantonov


Using the following SQL query in descriminator formula 

(select distinct ldt.`TYPE_NAME`  from `LIST_DATA_TYPE` ldt where ldt.`LIST_DATA_TYPE_ID` = `LIST_DATA_TYPE_ID`)

result it 

(select distinct ldt.listdata0_."TYPE_NAME"  from listdata0_."SF_LIST_DATA_TYPE" ldt where ldt.listdata0_."LIST_DATA_TYPE_ID" = listdata0_."LIST_DATA_TYPE_ID")

instead of 


(select distinct ldt."TYPE_NAME"  from "SF_LIST_DATA_TYPE" ldt where "LIST_DATA_TYPE_ID" = listdata0_."LIST_DATA_TYPE_ID")

The quotes are needed so that the same SQL will work on Oracle and Postgresql (where the later expects all lower case table names/ column names if not using quotes)

Possible solution:

in org.hibernate.sql.Template change the code on line 180 

from 
if (isOpenQuote) {


to

if (isOpenQuote && !inFromClause && (previousToken == null || !previousToken.endsWith("."))) {

note that the previousToken is a new variable that tracks previous tokens.

Using this if clause will not place a prefix on the table because of !inFromClause and it will not add prefix on all ldt. places - e.g. when we already specified to which table the column that we refers belongs to.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list