[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2692) Allow select clause to specify parameters

Ho Tri Bao (JIRA) noreply at atlassian.com
Thu Jan 6 23:24:05 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2692?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39502#action_39502 ] 

Ho Tri Bao commented on HHH-2692:
---------------------------------

I hit the same problem. It seems to me this is the problem of parsing the query (either sql or hql) in hibernate. When parsing the column list in the "select" statement, for each column, it needs to determine the type. So, when we use a parameter (either named parameter or index parameter) in column list clause, hibernate cannot know the type (the type can only be known when the real parameter is set), then it just stop parsing to the next columns (that's why the message "number of select types did not match those for insert").

Isn't it a bug? Is there anyway to hint hibernate query parser the type of a column?

I found a simple workaround (based on the idea of hinting hibernate the type). If your parameter (in the column list clause) is a string, don't put put it alone, put it in a string function instead. For example:

select :aStringParam||'', column_2, coumn_3
from a_table

> Allow select clause to specify parameters
> -----------------------------------------
>
>                 Key: HHH-2692
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2692
>             Project: Hibernate Core
>          Issue Type: New Feature
>          Components: query-hql
>    Affects Versions: 3.2.4.sp1
>         Environment: Hibernate 3.2.4.sp1 with Annotations 3.3.0 And Validator 3.0.0
> MySQL 5.0.42
>            Reporter: John Aylward
>            Priority: Minor
>
> receive exception:
> org.hibernate.QueryException: number of select types did not match those for insert [INSERT INTO ProviderInvoiceLineItem (amount,billingAccount,circuit,description,invoice,type) SELECT pili.amount, pili.billingAccount, pili.circuit, pili.description, :newInvoice, pili.type FROM com.cicat.bedrock.billing.model.ProviderInvoiceLineItem pili WHERE pili.invoice = :oldInvoice]
> Idea is to copy all line items from one invoice to another. In other words, only difference between data should be the invoice. easiest way to do this is with "insert into" command and passing parameter of changed value.
>  * Trying to cast named parameter (:newInvoice) caused parsing error
>  * Trying to replace invoice with invoice_id and repacing :newInvoice with actual invoice id resulted in a "property 'invoice_id' not found" exception
> Should be able to set a value through a named parameter

-- 
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