-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate tools generating association error
PostPosted: Mon Feb 25, 2013 1:29 am 
Newbie

Joined: Sun Feb 24, 2013 7:57 pm
Posts: 3
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:hbm2cfgxml goal I get the following error:

Code:
An association from the table FOO refers to the unmapped class com.whatever.domain.Bar


My maven project file looks like this:

Code:
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <components>
      <component>
        <name>hbm2cfgxml</name>
        <implementation>jdbcconfiguration</implementation>
        <outputDirectory>target/classes</outputDirectory>
      </component>
    </components>
    <componentProperties>
      <propertyfile>src/main/resources/database.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 database.properties file contains the following:

Code:
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 a hibernate configuration file 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 hbm2cfgxml goal is successful. If I specify the tables FOO, BAR, and QUX in a reveng.xml file, then the hbm2cfgxml goal is successful. But if tables FOO, BAR, BAZ, and QUX are specified then the hbm2cfgxml 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?

I'm thinking that one solution may be to create a *.reveng.file and list each table in the correct order. Or perhaps run two iterations: one where the reveng.xml file specifies all tables except BAZ, and one where the reveng.xml specifies only the table BAZ.

But I'd really prefer not to do that since I am trying to automate the code generation as much as possible, and my reveng.xml file should only specify the schema and not the tables within that schema.

edit: I have a partial solution that is an ugly hack: I set up two profiles in maven, where each profile points to a different reveng.xml file. The first profile specifies a reveng.xml file that includes all tables in the schema except for the table BAZ. The second profile specifies a reveng.xml file that only includes the table BAZ. I then run mvn hibernate3:hbm2java -Pprofile1 and mvn hibernate3:hbm2java -Pprofile2 to get the full set of java files.

This will not work for the hbm2cfgxml goal, since it will generate different hibernate.cfg.xml files. There must be a way to generate a hibernate.cfg.xml file that simply reads the database properties without contacting the database, and which can also specify a package name for mapping?

edit: creating two profiles so that file generation is partitioned is not be a good hack, either. I am getting the association error when loading the annotated classes into Hibernate. And if I try generating mapping files then I get a "foreign key must have same number of columns as referenced primary key" error. It could be that some information is lost this way, information that is needed for consistency. Sigh.

edit: I'm wondering if the problem here is that FOO references foreign keys 'a' and 'b' in BAR, but those columns in BAR are foreign keys in BAZ and QUX respectively. Would the problem be solved if FOO references foreign key 'a' in BAZ and 'b' in QUX directly?

edit: I also ran hibernate tools under ant and got the same problem, so it's not a maven or hibernate3 plugin issue.


Last edited by johnqcitizen on Thu Mar 21, 2013 2:34 am, edited 7 times in total.

Top
 Profile  
 
 Post subject: Re: hbm2cfgxml generating association error
PostPosted: Wed Feb 27, 2013 7:13 pm 
Newbie

Joined: Sun Feb 24, 2013 7:57 pm
Posts: 3
I added some additional information about foreign keys, for clarity.

I still think this should just work out of the box, unless my hibernate3-maven-plugin configuration is incorrect.


Top
 Profile  
 
 Post subject: Re: Hibernate tools generating association error
PostPosted: Tue May 28, 2013 4:01 pm 
Newbie

Joined: Fri May 24, 2013 3:45 pm
Posts: 3
I am having a similar issue. I actually get that error on my many to many relationships. I tried using the eclipse plugin and disable the many-to-many detection (I don't know how to do that on ant task) and it's working fine, but not generating the many to many annotations (obviously).

Any hints on why this is not working?

My DB is a PostgresSQL 9.2 and using hibernatetools 4.0.0-CR1.

Thanks in advance!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.