-->
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.  [ 5 posts ] 
Author Message
 Post subject: Same foreign key pointing to many tables - middlegen
PostPosted: Mon Dec 06, 2004 3:25 am 
Newbie

Joined: Fri Nov 26, 2004 2:59 am
Posts: 5
Hibernate version: 2.1.6

Middlegen: 2.1

Oracle 9i

Hi

In our database model we have a DESCRIPTION table for text internationalisation. This table has a FOREIGNNODE_ID columns which is defined as the foreign key for many other tables.
In the mapping file of each of these tables, there is a set pointing to the column FOREIGNNODE_ID of the DESCRIPTION table, together with a one-to-many association.

The problem is that Migglegen generates a Description.hmb.xml file with many times the same property foreignNodeId (as many as the number of tables the foreign key points to). This results no compilable Java code (many properties with the same name in the class Description.java).

Is there any way to 'tell' Middlegen not to produce more than one property with the same name in a mapping file?

Thanks for help/hints
Fab


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 5:41 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I don't know Midlegen.

Writing the mapping by hand I'd say have a look at the any mapping tags.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Can you please provide the basic schema and a short snap shot of the output. I want to have a clear understanding of the relationships involved. Middlegen should be able to manage it fine. I'll (try to) fix it if it cannot not.


Top
 Profile  
 
 Post subject: Same foreign key pointing to many tables - middlegen
PostPosted: Tue Dec 07, 2004 3:57 am 
Newbie

Joined: Fri Nov 26, 2004 2:59 am
Posts: 5
Hi

I can reproduce this issue with the following mini table model (Oracle DDL).

Thanks in advance for help.
Fab


The table DESCRIPTION has a foriegn key defined on the tables ROLE and RULETYPE:
Code:
create table DESCRIPTION (
   DESCRIPTION_ID NUMBER(38,0) not null,
   "DESCRIPTOR" VARCHAR2(64) not null,
   KNOWN_FROM DATE not null,
   KNOWN_TO DATE null,
   VALID_FROM DATE not null,
   VALID_TO DATE null,
   MUTATION_ID NUMBER(38,0) not null,
   VALIDITYCODE CHAR(1) null,
   LANGUAGE_ID NUMBER(38,0) not null,
   FOREIGNTABLE_ID NUMBER(38,0) not null,
   FOREIGNNODE_ID NUMBER(38,0) null,
   SUMMARY VARCHAR2(256) not null,
   FULLTEXT VARCHAR2(2000) null, constraint DESCRIPTION_PK primary key (DESCRIPTION_ID) );

create table ROLE (
   ROLE_ID NUMBER(38,0) not null,
   KNOWN_FROM DATE not null,
   KNOWN_TO DATE null, constraint ROLE_PK primary key (ROLE_ID) );

create table RULETYPE (
   RULETYPE_ID NUMBER(38,0) not null,
   "DESCRIPTOR" VARCHAR2(64) not null,
   KNOWN_FROM DATE not null,
   KNOWN_TO DATE null,
   VALID_FROM DATE not null,
   VALID_TO DATE null,
   RULELEVEL CHAR(1) null, constraint RULETYPE_PK primary key (RULETYPE_ID) );

alter table DESCRIPTION
   add constraint RULETYPE_DESC_FK1 foreign key (
      FOREIGNNODE_ID)
    references RULETYPE (
      RULETYPE_ID);

alter table DESCRIPTION
   add constraint ROLE_DESC_FK1 foreign key (
      FOREIGNNODE_ID)
    references ROLE (
      ROLE_ID);


Here my Middlegen ant target (without taskdef):
Code:
<target
        name="test.middlegen"
        description="Run Middlegen and generate Hibernate mapping files.">

        <middlegen
            appname="Toolset"
            prefsdir="${basedir}/test_prefs"
            xmlprefs="true"
            databaseurl="${db.url}"
            gui="true"
            schema="mySchema"
            driver="oracle.jdbc.driver.OracleDriver"
            username="USER"
            password="PASSWORD">
           
      <table name="DESCRIPTION"/>   
        <table name="ROLE"/>                     
      <table name="RULETYPE"/>

            <hibernate
                destination="${test.dir}"
                databaseSchema="mySchema"
                package="mytest.server.persistence.mapping"/>

        </middlegen>

    </target>


Here comes the pref file of middlegen:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>

<preferences EXTERNAL_XML_VERSION="1.0">
  <root type="user">
    <map />
    <node name="middlegen">
      <map />
      <node name="Toolset">
        <map />
        <node name="hibernate">

         ... I removed table description ...

        </node>
        <node name="relations">
          <map />
          <node name="ROLE-DESCRIPTION">
            <map />
            <node name="DESCRIPTION-has-ROLE">
              <map>
                <entry key="target-many" value="false" />
                <entry key="enabled" value="false" />
              </map>
            </node>
            <node name="ROLE-has-DESCRIPTION">
              <map>
                <entry key="target-many" value="true" />
                <entry key="enabled" value="true" />
              </map>
            </node>
          </node>
          <node name="RULETYPE-DESCRIPTION">
            <map />
            <node name="DESCRIPTION-has-RULETYPE">
              <map>
                <entry key="target-many" value="false" />
                <entry key="enabled" value="false" />
              </map>
            </node>
            <node name="RULETYPE-has-DESCRIPTION">
              <map>
                <entry key="target-many" value="true" />
                <entry key="enabled" value="true" />
              </map>
            </node>
          </node>
        </node>

     ... table location in the gui ...

      </node>
    </node>
  </root>
</preferences>



Here comes the mapping file for the table DESCRIPTION, which middelgen has generated.
As you can see, the property FOREIGNNODE_ID is declared twice in the file. The generated Java class has then twice the property + setter/getter.


Code:
<hibernate-mapping>
<class
    name="mytest.server.persistence.mapping.Description"
    table="DESCRIPTION"
    schema="mySchema"
>
    <id
        name="descriptionId"
        type="java.math.BigDecimal"
        column="DESCRIPTION_ID"
    >
        <generator class="assigned" />
    </id>

    ... properties not involved in the mapping are removed ...

    <!-- Associations -->
 
    <property
        name="foreignnodeId"
        column="FOREIGNNODE_ID"
        type="java.math.BigDecimal"
        length="38"
    >
    </property>
    <property
        name="foreignnodeId"
        column="FOREIGNNODE_ID"
        type="java.math.BigDecimal"
        length="38"
    >
    </property>

</class>
</hibernate-mapping>


Mapping for the ROLE table:
Code:
<hibernate-mapping>

<class
    name="mytest.server.persistence.mapping.Role"
    table="ROLE"
    schema="TMS"
>
    <id
        name="roleId"
        type="java.math.BigDecimal"
        column="ROLE_ID"
    >
        <generator class="assigned" />
    </id>

        ... properties not involved in the mapping are removed ...

    <!-- Associations -->
 
    <!-- uni-directional one-to-many association to Description -->
    <set
        name="descriptions"
        lazy="true"
      cascade="none"
    >
        <key>
            <column name="FOREIGNNODE_ID" />
        </key>
        <one-to-many
            class="mytest.server.persistence.mapping.Description"
        />
    </set>
</class>
</hibernate-mapping>


Mapping for the RULETYPE table:
Code:
<hibernate-mapping>

<class
    name="mytest.server.persistence.mapping.Ruletype"
    table="RULETYPE"
    schema="TMS"
>
    <id
        name="ruletypeId"
        type="java.math.BigDecimal"
        column="RULETYPE_ID"
    >
        <generator class="assigned" />
    </id>
   
    ... properties not involved in the mapping are removed ...


    <!-- Associations -->
 
    <!-- uni-directional one-to-many association to Description -->
    <set
        name="descriptions"
        lazy="true"
      cascade="none"
    >
        <key>
            <column name="FOREIGNNODE_ID" />
        </key>
        <one-to-many
            class="mytest.server.persistence.mapping.Description"
        />
    </set>

</class>
</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 7:12 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I think that you have to add different foreign key for every tables

regards


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