<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/Using+Teiid+with+Hibernate">Using Teiid with Hibernate</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~van.halbert">Van Halbert</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h1. Configuration <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">For the most part, interacting with Teiid VDBs (Virtual Databases) from Hibernate is no different from working with any other type of data source.  First you must place Teiid JDBC API client JAR file and Teiid&#39;s hibernate dialect JAR in Hibernate’s classpath.  These files can be found in {{&lt;jboss-install&gt;/server/&lt;profile&gt;/lib}} directory. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">For the most part, interacting with Teiid VDBs (Virtual Databases) through Hibernate is no different from working with any other type of data source.&amp;nbsp; First, depending on where your Hibernate application will reside, either in the same VM as the Teiid Runtime or on a separate VM, will determine which jar&#39;s are used.&amp;nbsp; <br>* Running in same VM in the JBoss AS server, then the teiid-client-{version}.jar and teiid-hibernate-dialect-{version}.jar already reside in &lt;jboss-install&gt;/modules/org/jboss/teiid/client <br>* Running separate VM&#39;s,you need the Teiid JDBC Driver JAR and Teiid&#39;s Hibernate Dialect JAR in the Hibernate&#39;s classpath.&amp;nbsp; The Hibernate JAR can be found in &lt;jboss-install&gt;/modules/org/jboss/teiid/client, teiid-hibernate-dialect-{version}.jar and the [Teiid JDBC Driver JAR|http://www.jboss.org/teiid/downloads.html] needs to be downloaded. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* teiid-\{version}-jdbc.jar <br>* teiid-hibernate-dialect-\{version}.jar <br> <br></td></tr>
            <tr><td class="diff-unchanged" >These JAR files have the {{org.teiid.dialect.TeiidDialect}} and {{org.teiid.jdbc.TeiidDriver}} and {{org.teiid.jdbc.TeiidDataSource}} classes. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >You <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">then</span> configure Hibernate (via hibernate.cfg.xml) as follows: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* Specify the Teiid driver class in the &quot;connection.driver_class&quot; property: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="UsingTeiidwithHibernate-Limitations"></a>Limitations</h1>

<ul>
        <li>Many Hibernate use cases assume a data source has the ability (with proper user permissions) to process Data Definition Language (DDL) statements like CREATE TABLE and DROP TABLE as well as Data Manipulation Language (DML) statements like SELECT, UPDATE, INSERT and DELETE. Teiid can handle a broad range of DML, but does not directly support DDL against a particular source.</li>
</ul>


<ul>
        <li>Sequence and Identity generation are not supported. Identifier generation based upon table values, such as the hilo generator, require that the identifier table(s) be exposed through Teiid. The GUID identifier generation strategy is directly supported.</li>
</ul>



<h1><a name="UsingTeiidwithHibernate-Configuration"></a>Configuration</h1>

<p>For the most part, interacting with Teiid VDBs (Virtual Databases) through Hibernate is no different from working with any other type of data source.&nbsp; First, depending on where your Hibernate application will reside, either in the same VM as the Teiid Runtime or on a separate VM, will determine which jar's are used.&nbsp;</p>
<ul>
        <li>Running in same VM in the JBoss AS server, then the teiid-client-
<div class="error"><span class="error">Unknown macro: {version}</span> <p>.jar and teiid-hibernate-dialect-</p></div>
<p>.jar already reside in &lt;jboss-install&gt;/modules/org/jboss/teiid/client</p></li>
        <li>Running separate VM's,you need the Teiid JDBC Driver JAR and Teiid's Hibernate Dialect JAR in the Hibernate's classpath.&nbsp; The Hibernate JAR can be found in &lt;jboss-install&gt;/modules/org/jboss/teiid/client, teiid-hibernate-dialect-
<div class="error"><span class="error">Unknown macro: {version}</span> </div>
<p>.jar and the <a href="http://www.jboss.org/teiid/downloads.html" class="external-link" rel="nofollow">Teiid JDBC Driver JAR</a> needs to be downloaded.</p></li>
</ul>


<p>These JAR files have the <tt>org.teiid.dialect.TeiidDialect</tt> and <tt>org.teiid.jdbc.TeiidDriver</tt> and <tt>org.teiid.jdbc.TeiidDataSource</tt> classes.</p>

<p>You configure Hibernate (via hibernate.cfg.xml) as follows:</p>

<ul>
        <li>Specify the Teiid driver class in the "connection.driver_class" property:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;property name="connection.driver_class"&gt;
     org.teiid.jdbc.TeiidDriver
&lt;/property&gt;
</pre>
</div></div></li>
</ul>


<ul>
        <li>Specify the URL for the VDB in the "connection.url" property (replacing terms in angle brackets with the appropriate values):</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;property name="connection.url"&gt;
        jdbc:teiid:&lt;vdb-name&gt;@mm://&lt;host&gt;:&lt;port&gt;;user=&lt;user-name&gt;;password=&lt;password&gt;
&lt;/property&gt;
</pre>
</div></div>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Be sure to use a <a href="/author/display/TEIID/JBoss+AS+Data+Source#JBossASDataSource-LocalJDBCConnection">Local JDBC Connection</a> if Hibernate is in the same VM as the application server.</td></tr></table></div>

<ul>
        <li>Specify the Teiid dialect class in the “dialect” property:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;property name="dialect"&gt;
        org.teiid.dialect.TeiidDialect
&lt;/property&gt;
</pre>
</div></div>

<p>Alternatively, if you put your connection properties in <tt>hibernate.properties</tt> instead of <tt>hibernate.cfg.xml</tt>, they would look like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">hibernate.connection.driver_class=org.teiid.jdbc.TeiidDriver
hibernate.connection.url=jdbc:teiid:&lt;vdb-name&gt;@mm://&lt;host&gt;:&lt;port&gt;
hibernate.connection.username=&lt;user-name&gt;
hibernate.connection.password=&lt;password&gt;
hibernate.dialect=org.teiid.dialect.TeiidDialect
</pre>
</div></div>

<p>Note also that since your VDBs will likely contain multiple source and view models with identical table names, you will need to fully qualify table names specified in Hibernate mapping files:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;class name="&lt;Class name&gt;" table="&lt;Source/view model name&gt;.[&lt;schema name&gt;.]&lt;Table name&gt;"&gt;
        ...
&lt;/class&gt;
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example Mapping</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;class name="org.teiid.example.Publisher" table="BOOKS.BOOKS.PUBLISHERS"&gt;
        ...
&lt;/class&gt;
</pre>
</div></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/Using+Teiid+with+Hibernate">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646138&revisedVersion=6&originalVersion=5">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Using+Teiid+with+Hibernate?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>