<!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;">
    Getting "association error" when reverse-engineering an existing schema with Hibernate tools
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/johnqcitizen">John Citizen</a> in <i>JBoss Tools</i> - <a href="https://community.jboss.org/message/801484#801484">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I'm connecting to a production Oracle 10g database and attempting to generate a Hibernate configuration file using the hibernate3-maven-plugin running in Maven.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>However when I run the hibernate3:hbm2java goal I get the following error: An association from the table FOO refers to the unmapped class com.whatever.domain.Bar</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My maven project file looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&lt;plugin&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;artifactId&gt;hibernate3-maven-plugin&lt;/artifactId&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;version&gt;2.2&lt;/version&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;configuration&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;components&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;component&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;name&gt;hbm2java&lt;/name&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;implementation&gt;jdbcconfiguration&lt;/implementation&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;outputDirectory&gt;target/classes&lt;/outputDirectory&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;/component&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;/components&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;componentProperties&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;propertyfile&gt;src/main/resources/hibernate.properties&lt;/propertyfile&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;/componentProperties&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;/configuration&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;dependencies&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;dependency&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;groupId&gt;com.oracle&lt;/groupId&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;artifactId&gt;ojdbc&lt;/artifactId&gt; </span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;version&gt;11.1.0.6.0&lt;/version&gt; </span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;/dependency&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;dependency&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;groupId&gt;cglib&lt;/groupId&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;artifactId&gt;cglib-nodep&lt;/artifactId&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160;&#160;&#160; &lt;version&gt;2.1_3&lt;/version&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160;&#160;&#160; &lt;/dependency&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&#160; &lt;/dependencies&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">&lt;/plugin&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> My <strong>hibernate.properties</strong> file contains the following:</p><p>&#160; </p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">hibernate.connection.url=jdbc:oracle:thin:@&lt;server&gt;:&lt;host&gt;:&lt;db&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">hibernate.connection.username=&lt;username&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">hibernate.connection.password=&lt;password&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">hibernate.dialect=org.hibernate.dialect.Oracle10gDialect</span></p><p style="padding-left: 30px;"><span style="font-family: 'courier new', courier;">hibernate.default_schema=&lt;schema&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Because this is a production database, then I assume that the schema is sound and expect the <strong>hibernate3-maven-plugin</strong> to extract that schema and generate annotated java files without error.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I've narrowed down the offending tables to the following:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="padding-left: 30px;"><strong style="font-family: arial, helvetica, sans-serif;">&#160; FOO</strong></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - foreign key 'a' in BAR</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - foreign key 'b' in BAR</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - foreign key 'c' in QUUX</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - primary key is composite of foreign keys 'a', 'b' in BAR and foreign key 'c' in QUUX</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 style="padding-left: 30px;"><strong style="font-family: arial, helvetica, sans-serif;">&#160; BAR </strong></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - foreign key 'a' in BAZ</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - foreign key 'b' in QUX</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160;&#160;&#160; - primary key is a composite of the foreign key 'a' in BAZ and foreign key 'b' in QUX</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 style="padding-left: 30px;"><strong style="font-family: arial, helvetica, sans-serif;">&#160; BAZ</strong></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160; - primary key 'a'</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160; - no foreign keys</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 style="padding-left: 30px;"><strong style="font-family: arial, helvetica, sans-serif;">&#160; QUX</strong></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160; - primary key 'b'</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160; - no foreign keys</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="padding-left: 30px;"><strong style="font-family: arial, helvetica, sans-serif;">&#160; QUUX</strong></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160; - primary key 'c'</span></p><p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif;">&#160; - no foreign keys</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>If I specify the tables FOO, BAR and BAZ in a <strong>reveng.xml</strong> file, then the <strong>hbm2java</strong> goal is successful. If I specify the tables FOO, BAR, and QUX in a <strong>reveng.xml</strong> file, then the <strong>hbm2java</strong> goal is successful. But if tables FOO, BAR, BAZ, and QUX are specified then the <strong>hbm2java</strong> goal fails with the aforementoned association error between FOO and com.whatever.domain.Bar file. That is, if both tables representing the foreign keys in BAR are present, then the goal fails. If just one foreign key table is present, then the goal succeeds.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any suggestions on what is causing the problem, and how to fix it? </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/801484#801484">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>