<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Using hibernate Tools to generate Sql Script
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/chetansh">Chetan Shinde</a> in <i>JBoss Tools</i> - <a href="https://community.jboss.org/message/797369#797369">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>We wanted to generate SQL Script (DDL) from POJO class which are Hibernate Annotated. I have tried using both <span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">hibernate3 maven plugin as well as with the Schema Exporter. </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Now this class also has a Sequecne Generator defined, and I was expecting that there would be a Sequence script generated for it as well. <br/></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This is what the code looked like in the Entity with respect to the Sequence, the allocationSize here is defined as 50, I have tried using all different sizes.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>@Entity @SequenceGenerator(name="sessionInfoIdSeq", sequenceName="SESSIONINFO_ID_SEQ", allocationSize=50)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class SessionInfo {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><code><span class="lit">@Id</span><span class="pln">&#160; </span><span class="lit">@GeneratedValue</span><span class="pun">(</span><span class="pln">strategy </span><span class="pun">=</span><span class="pln"> </span><span class="typ">GenerationType</span><span class="pun">.</span><span class="pln">AUTO</span><span class="pun">,</span><span class="pln"> generator</span><span class="pun">=</span><span class="str">"sessionInfoIdSeq"</span><span class="pun">)</span><span class="pln"><br/></span><span class="kwd">private</span><span class="pln"> </span><span class="typ">Integer</span><span class="pln">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; id</span><span class="pun">;</span></code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span class="pun">I am using following JARS:</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><br/>I am using the following jars : hibernate-tools - 3.2.4.GA, hibernate-core - 3.6.1.Final, hibernate-entitymanager - 3.6.1.Final, hibernate-validator - 4.1.0.Final, hibernate-validator-legacy - 4.0.2.GA and DB related jars.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now when I tried debugging the code using the SchemaExporter example I found that the class in hibernate-core jar was getting called for generating the sequence text.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The problem is that it was only creating create sequence SESSIONINFO_ID_SEQ;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>At line 146 on SequenceGenerator.java it was using </p><p><em style="font-size: 12.0pt; font-family: 'Times New Roman','serif';">String[] ddl =</em><span style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"> <em>dialect.getCreateSequenceStrings(sequenceName) from the Dialect class which happened to be deprecated.</em></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This method implementation was </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="background: white;"> <em>public String[]&#160; getCreateSequenceString(String sequenceName) {</em></p><p style="background: white;"><em> </em></p><p style="background: white;"><em> return "create sequence " + sequenceName; //starts with 1, implicitly</em></p><p style="background: white;"><em> </em></p><p style="background: white;"><em> }&#160; </em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"><em>The Dialect API said instead to usefollowing method.<br/></em></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>protected String&#160; getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) throws MappingException { </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( supportsPooledSequences() ) { </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return getCreateSequenceString( sequenceName ) + " start with " + initialValue + " increment by " + incrementSize;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new MappingException( "Dialect does not support pooled sequences" );</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I checked the latest APi of the hibernate-core and it too uses the deprecated method.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any inputs on this would be appreciated.&#160; Do I need to raise a JIRA?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have attached a sample example that I used to&#160; generate the Code, SchemaExporter.7z.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Regards,</p><p>Chetan</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/797369#797369">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Tools at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>