How to automatically convert the Integer Parameters of hql statements in ValueList by configuring

Source: Internet
Author: User

The parameters passed through queryMap of valuelist are of the string type by default. In hql of the valuelist configuration file, an error is returned if this value is directly assigned to an integer field. We generally use transformation functions in hql for processing, as shown below:
Copy codeThe Code is as follows:
<Entry key = "areasInfoAdapter">
<Bean parent = "maid">
<Property name = "defaultNumberPerPage"> <value> 19 </value> </property>
<Property name = "statementBuilder"> <ref bean = "statementBuilderHql"/> </property>
<Property name = "defaultSortColumn"> <value> id </value> </property>
<Property name = "defaultSortDirection"> <value> desc </value> </property>
<Property name = "hql">
<Value>
From com. berheley. hcms. persistence. model. TBaseAreas as tb
Where tb. status = '1'
/~ HId: and tb. hId = to_number {hId }~ /
/~ OId: and tb. oId = to_number {oId }~ /
Order by tb. code asc
</Value>
</Property>
<Property name = "defaultFocusPropertyObjectAlias"> <value> vo </value> </property>
<Property name = "maxRowsForFocus"> <value> 160000 </value> </property>
<Property name = "removeEmptyStrings"> <value> true </value> </property>
</Bean>
</Entry>

This method is troublesome. function processing must be added to all integer fields, and function incompatibility may occur during database migration. You can use the ValueList configuration to uniformly set integer fields. valuelist will transform the configured parameters before assembling SQL statements. As follows:
Copy codeThe Code is as follows:
<Bean id = "integerSetterHql" class = "net. mlw. vlh. adapter. hibernate3.util. setter. IntegerSetter"> </bean>
<Bean id = "statementBuilderHql" class = "net. mlw. vlh. adapter. hibernate3.util. StatementBuilder">
<Property name = "setters">
<Map>
<Entry key = "uId"> <ref bean = "integerSetterHql"/> </entry>
<Entry key = "oId"> <ref bean = "integerSetterHql"/> </entry>
</Map>
</Property>
</Bean>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.