-->
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.  [ 2 posts ] 
Author Message
 Post subject: problems with generated foreign keys
PostPosted: Mon Dec 18, 2006 9:06 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
hello!

following class structrure: two classes 'ReqTest' and 'TRefTest', both subclasses of 'ProjectPersModelWithCreation' (in this example both classes are equal). both classes have a set of 'ModelCoverage' and this class references the superclass 'ProjectPersModelWithCreation':
Code:
<class
        name="com.seqis.kltm.model.db.abstracts.ProjectPersModelWithCreation"
        table="persistent_model"
    >

        <id
            name="objectId"
            column="object_id"
            type="long"
        >
            <generator class="native">
            </generator>
        </id>

        <joined-subclass
            name="com.seqis.kltm.model.db.project.ReqTest"
            table="req_test"
        >
            <key
                column="object_id"
            />
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="name"
        />

        <set
            name="modelCoverage"
            lazy="false"
            cascade="save-update"
            sort="unsorted"
        >

            <key
                column="referencer_id"
            >
            </key>

            <one-to-many
                  class="com.seqis.kltm.model.db.project.ModelCoverage"
            />

        </set>

        </joined-subclass>

        <joined-subclass
            name="com.seqis.kltm.model.db.project.TRefTest"
            table="tref_test">

        <key
              column="object_id"
        />
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="name"
        />

        <set
            name="modelCoverage"
            lazy="false"
            cascade="save-update"
            sort="unsorted"
        >

            <key
                column="referencer_id"
            >
            </key>

            <one-to-many
                  class="com.seqis.kltm.model.db.project.ModelCoverage"
            />

        </set>

        </joined-subclass>


Code:
<class
        name="com.seqis.kltm.model.db.project.ModelCoverage"
        table="model_coverage"
    >

        <id
            name="objectId"
            column="object_id"
            type="long"
        >
            <generator class="native">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-ModelCoverage.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <property
            name="comment"
            type="java.lang.String"
            update="true"
            insert="true"
            column="comment"
            length="8192"
        />

        <many-to-one
            name="referenced"
            class="com.seqis.kltm.model.db.abstracts.ProjectPersModelWithCreation"
            cascade="all"
            outer-join="auto"
            update="true"
            insert="true"
            column="referenced_id"
            not-null="true"
        />

        <many-to-one
            name="referencer"
            class="com.seqis.kltm.model.db.abstracts.ProjectPersModelWithCreation"
            cascade="all"
            outer-join="auto"
            update="true"
            insert="true"
            column="referencer_id"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-ModelCoverage.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>


my problem is, that the hibernate generates two has two foreign keys for the field 'referencer' in the object 'ModelCoverage', one to 'ReqTest' and one to 'TRefTest', but the only foreign key should reference the superclass 'ProjectPersModel...', because the field cannot reference two different tables at the same time...

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 10:23 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
same problem, but a little bit easier to understand:

entities A, B and C. A and B reference C. is there a possiblity to use only one column in C for this reference, which means, that hibernate should not create the foreign key constraints to A and B for this column?

edit: is there a way to control the foreign key generation of hibernate?


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