Category: 

What Are Native Queries?

Article Details
  • Written By: Jean Marie Asta
  • Edited By: Jessica Seminara
  • Last Modified Date: 24 August 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
The atmosphere of Jupiter's moon Io collapses every time it is eclipsed by the planet.   more...

September 29 ,  2008 :  The Dow Jones Industrial Average experienced its largest one-day drop in history.  more...

Native queries are queries expressed through Structured Query Language (SQL) and are concise as well as type-safe methods of C++ and Java query expression. The use of native queries is beneficial in utilization of specific features in databases, including query hints and certain database-specific features. They are also useful in providing clean paths of migration directly from applications using SQL or Java Database Connectivity (JDBC™). Native queries are used to provide results consisting of scalar values, entities or both. These types of queries support the use of native SQL on a target database.

These types of queries can overcome a string-based application programming interface’s (API’s) shortcomings. Queries of this kind are used in an object database, where object persistence is a common task for programmers and a common feature of the database. Non-native queries, however, appear foreign in programs that are object-oriented due to their expressions being simple strings and object graphs containing interspersed strings.

Native queries help alleviate the problems faced in databases by expressing a query within Java and C++. Queries can be written without an API or a customized query language. In addition, an Integrated Development Environment (IDE) is able to aid in the reduction of typos. The native queries would then be type-safe to the fullest and able to be accessed by an IDE’s refactoring features. Finally, the queries can be run, tested and prototyped against plain memory collections without the back end of a database.

Ad

The queries, and their accompanying SQL, are not necessarily transferrable across other databases. Upon the return of many entities by a particular native query, these same entities should be specified, as well as mapped, to column results in SQL statements in a metadata definition mapping software program. As a result, these may be used to map JDBC results by persistent runtime into expected objects. Name parameter use is never defined for these types of queries and portable applications can only use binding of positional parameters for native SQL queries. Support of joins is limited to relationships of single values.

To use native queries, a programmer must describe a SQL result set. Describing the result set helps a program such as Entitymanager map columns onto properties of entities. Scalar results may also be defined and mixed with other entity results, resulting in a return of an alias column. Once result sets are described, execution of native queries is possible.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

exception 'Exception' with message 'error writing captcha: Duplicate entry '2147483647' for key 'PRIMARY'' in /ssd/www/wisegeek/public_html/_core/classes/public/Captcha.php:44
Stack trace:
#0 /ssd/www/wisegeek/public_html/_core/controls/public/ControlDiscussionPostBox.php(324): Captcha->createCaptcha()
#1 /ssd/www/wisegeek/public_html/framework/classes/Control.php(104): ControlDiscussionPostBox->preRender(false)
#2 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): Control->render()
#3 /ssd/www/wisegeek/public_html/tpl/default-nocustom-lu/pages/public/article/article.htm(526): Control->__toString()
#4 /ssd/www/wisegeek/public_html/framework/classes/Control.php(300): require('/ssd/www/wisege...')
#5 /ssd/www/wisegeek/public_html/framework/classes/Control.php(309): Control->requireTpl('pages/public/ar...', Object(PageArticleCom), true)
#6 /ssd/www/wisegeek/public_html/framework/classes/Control.php(131): Control->renderTpl('pages/public/ar...', Object(PageArticleCom))
#7 /ssd/www/wisegeek/public_html/framework/classes/FormDataControl.php(87): Control->renderTemplate()
#8 /ssd/www/wisegeek/public_html/framework/classes/Control.php(109): FormDataControl->renderTemplate()
#9 /ssd/www/wisegeek/public_html/framework/classes/ScriptPage.php(50): Control->render(false)
#10 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): ScriptPage->render()
#11 /ssd/www/wisegeek/public_html/framework/classes/Page.php(97): Control->__toString()
#12 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(443): Page->processRequest()
#13 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(7): PublicFrontController->renderPage()
#14 /ssd/www/wisegeek/public_html/index.php(11): PublicFrontController::run()
#15 {main}