-->
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.  [ 4 posts ] 
Author Message
 Post subject: Reverse engineering fails to generate association
PostPosted: Thu Jun 25, 2009 7:38 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I'm probably making silly mistakes here, but I couldn't find the right documentation.

The problem is that I'm defining an association, but the reverse-engineering process ignores it.

Situation

Table G913 is a legacy table; it has no primary key but a unique key over the fields WGR and FI_NR.
Table REICHW is a table I'm free to redesign as needed. It uses the fields RWWGR and RWABC as primary key (I'm stripping the true list of PK fields here for brevity).

G913 provides human-readable texts for WGR codes.

Intent

I need to set up an association from REICHW to G913 so that the WGR texts become available.

As a JOIN condition, it would be written as
G913.WGR = REICHW.RWWGR AND G913.FI_NR = 1

My attempts

Here's my hibernate.reveng.xml (a pity that BBCode [ color ] doesn't work inside [ code ]):

Code:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
  <schema-selection match-schema="ECHT" />
  <table-filter match-name="HF_DI_.*" />
  <table-filter match-name="G913" />
  <table name="HF_DI_REICHW">
    <foreign-key constraint-name="reichw_g913" foreign-table="G913">
      <column-ref local-column="RWWGR" foreign-column="WGR" />
      <column-ref local-column="1" foreign-column="FI_NR" />
      <many-to-one fetch="join" />
    </foreign-key>
  </table>
  <table name="G913">
    <primary-key>
      <key-column name="WGR" /><key-column name="FI_NR" /></primary-key>
  </table>
</hibernate-reverse-engineering>


For some reason, Hibernate Tool doesn't generate anything from the <foreign-key> tag.

Final details

I'm using Oracle 9i.

I'm using annotations, not generating .hbm.xml.

No association annotations are generated with or without the primary key definition for G913.

Association annotations and the corresponding fields and accessors are defined for a pair of unrelated tables that have a database-defined foreign key constraint.

Any help appreciated

Top priority would be getting the thing to fly, but hints and tips on improving the above hibernate.reveng.xml would be appreciated as well.

TIA!


Last edited by Joachim Durchholz on Mon Jun 29, 2009 12:21 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Reverse engineering fails to generate association
PostPosted: Fri Jun 26, 2009 4:35 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
(Daily bump)
Clues, anybody?


Top
 Profile  
 
 Post subject: Re: [Solved] Reverse engineering fails to generate association
PostPosted: Fri Jun 26, 2009 7:27 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
The decisive hint was on https://jira.jboss.org/jira/browse/JBID ... n_12412934:

Specifying the default schema in hibernate.reveng.xml is not enough, it must also be specified as a property in hibernate.cfg.xml, like this:

Code:
<?xml version="1.0" encoding="utf-8"?>...
<hibernate-configuration>
    <session-factory name="">
        ...
        <property name="hibernate.default_catalog"></property>
        <property name="hibernate.default_schema">YOUR_SCHEMA_NAME</property>
        ...
    </session-factory>
</hibernate-configuration>


(Oracle does not have the concept of a catalog, so this needs to be specified as an empty string.)

(I consider this a bug and will try to report that via JIRA.)
(UPDATE: I can't register without activating Javascript, and I won't do that. I just had to reinstall Firefox to regain control over who's allowed to run JS in my browser and who isn't. In fact I'm generally weary of registration pages that require JS... I trust most people, but I know that in 1 of 20 cases I'm wrong, and the consequences of misplaced trust are too severe in today's times.)


Top
 Profile  
 
 Post subject: Re: Reverse engineering fails to generate association
PostPosted: Mon Jun 29, 2009 12:23 pm 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Just a note to those reading this - putting an empty hibernate.default_catalog property will make Hibernate generate table names such as .SCHEMA.TABLE, which later fails with "Invalid table name".

The reveng tool even honors associations now. (Probably it's enough to add hibernate.default_catalog.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.