John Citizen [
https://community.jboss.org/people/johnqcitizen] created the discussion
"Getting "association error" when reverse-engineering an existing schema
with Hibernate tools"
To view the discussion, visit:
https://community.jboss.org/message/801484#801484
--------------------------------------------------------------
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.
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
My maven project file looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>jdbcconfiguration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
</components>
<componentProperties>
<propertyfile>src/main/resources/hibernate.properties</propertyfile>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.1.0.6.0</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
My *hibernate.properties* file contains the following:
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@<server>:<host>:<db>
hibernate.connection.username=<username>
hibernate.connection.password=<password>
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.default_schema=<schema>
Because this is a production database, then I assume that the schema is sound and expect
the *hibernate3-maven-plugin* to extract that schema and generate annotated java files
without error.
I've narrowed down the offending tables to the following:
* FOO*
- foreign key 'a' in BAR
- foreign key 'b' in BAR
- foreign key 'c' in QUUX
- primary key is composite of foreign keys 'a', 'b' in BAR and foreign
key 'c' in QUUX
* BAR*
- foreign key 'a' in BAZ
- foreign key 'b' in QUX
- primary key is a composite of the foreign key 'a' in BAZ and foreign key
'b' in QUX
* BAZ*
- primary key 'a'
- no foreign keys
* QUX*
- primary key 'b'
- no foreign keys
* QUUX*
- primary key 'c'
- no foreign keys
If I specify the tables FOO, BAR and BAZ in a *reveng.xml* file, then the *hbm2java* goal
is successful. If I specify the tables FOO, BAR, and QUX in a *reveng.xml* file, then the
*hbm2java* goal is successful. But if tables FOO, BAR, BAZ, and QUX are specified then the
*hbm2java* 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.
Any suggestions on what is causing the problem, and how to fix it?
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/801484#801484]
Start a new discussion in JBoss Tools at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]