<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/JPA+Translator">JPA Translator</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://docs.jboss.org/author/display/~van.halbert">Van Halbert</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h1><a name="JPATranslator-"></a><font color="#000000"><b>JPA Translator</b></font></h1>

<p><font color="#333333">Think this one as a reverse to what Hibernate provides. If you have JPA based store and have a supporting object model, this translator can will reverse your object model into relational model, where you can integrate with other relational or non-relational sources.</font></p>

<h3><a name="JPATranslator-"></a><font color="#000000"><b>Native Queries</b></font></h3>

<p><font color="#333333">JPA source procedures may be created using the teiid_rel:native-query extension - see&nbsp;</font><font color="#005e8f">[<font color="#005e8f"></font>Parameterizable Native Queries</font>|#native]<font color=""><font color="#333333"></font>. The procedure will invoke the native-query similar to an native procedure call with the benefits that the query is predetermined and that result column types are known, rather than requiring the use of ARRAYTABLE or similar functionality.</font></p>

<h4><a name="JPATranslator-"></a><font color="#000000"><b>Native Procedure</b></font></h4>
<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><font color="#333333">This feature is turned off by default because of the security risk this exposes to execute any command against the source. To enable this feature, override the translator property called "SupportsNativeQueries" to true. Look for&nbsp;</font><font color="#005e8f">[<font color="#005e8f"></font>Override Execution Properties</font>|#Override Execution Properties]<font color=""><font color="#333333"></font>&nbsp;above.</font></td></tr></table></div>
<p><font color="#333333">JPA translator provides a procedure with name&nbsp;</font><font color="#333333"><b>native</b></font><font color="#333333">&nbsp;that gives ability to execute any ad-hoc native JPA-QL queries directly against the source without any Teiid parsing or resolving. Since the metadata of this procedure's execution results are not known to the Teiid and they are returned as object array. User can use&nbsp;</font><font color="#005e8f">[<font color="#005e8f"></font>ARRAYTABLE</font>|ARRAYTABLE]<font color=""><font color="#333333"></font>&nbsp;to construct a build a tabular output for consumption by client applications. Teiid exposes this procedure with a simple query structure as below</font></p>

<h5><a name="JPATranslator-"></a><font color="#000000"><b>Select</b></font></h5>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Select Example</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SELECT x.* FROM (call pm1.native('search;FROM Account')) w,
 ARRAYTABLE(w.tuple COLUMNS "id" string , "type" string, "name" String) AS x
</pre>
</div></div>
<p><font color="#333333">from the above code, the "</font><font color="#333333"><b>search</b></font><font color="#333333">" keyword followed by a query statement - see&nbsp;</font><font color="#005e8f">[<font color="#005e8f"></font>Parameterizable Native Queries</font>|#native]<font color=""><font color="#333333"></font>&nbsp;to substitute parameter values.</font></p>

<h5><a name="JPATranslator-"></a><font color="#000000"><b>Delete</b></font></h5>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Delete Example</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SELECT x.* FROM (call pm1.native('delete;&lt;jpa-ql&gt;')) w,
 ARRAYTABLE(w.tuple COLUMNS "updatecount" integer) AS x
</pre>
</div></div>
<p><font color="#333333">form the above code, the "</font><font color="#333333"><b>delete</b></font><font color="#333333">" keyword followed by JPA-QL for delete operation.</font></p>

<h5><a name="JPATranslator-"></a><font color="#000000"><b>Update</b></font></h5>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Create Example</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SELECT x.* FROM
 (call pm1.native('update;&lt;jpa-ql&gt;')) w,
 ARRAYTABLE(w.tuple COLUMNS "update_count" integer) AS x
</pre>
</div></div>
<p><font color="#333333">form the above code, the "</font><font color="#333333"><b>update</b></font><font color="#333333">" keyword must be followed by JPA-QL for the update statement.</font></p>

<h5><a name="JPATranslator-"></a><font color="#000000"><b>Create</b></font></h5>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Update Example</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SELECT x.* FROM
 (call pm1.native('create;', &lt;entity&gt;)) w,
 ARRAYTABLE(w.tuple COLUMNS "update_count" integer) AS x
</pre>
</div></div>
<p><font color="#333333">Create operation needs to send "</font><font color="#333333"><b>create</b></font><font color="#333333">" word as marker and send the entity as a the first parameter.</font></p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><font color="#333333">By default the name of the procedure that executes the queries directly is called&nbsp;</font><font color="#333333"><b>native</b></font><font color="#333333">, however user can</font><br/>
<font color="#333333">set override execution property vdb.xml file to change it.</font></td></tr></table></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
       <a href="https://docs.jboss.org/author/display/TEIID/JPA+Translator">View Online</a>
              |
       <a href="https://docs.jboss.org/author/display/TEIID/JPA+Translator?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>