-->
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.  [ 1 post ] 
Author Message
 Post subject: Wrong foreign key is generated
PostPosted: Tue Feb 26, 2008 8:18 pm 
Newbie

Joined: Thu Feb 21, 2008 12:55 pm
Posts: 4
Hello,

I do not know if my mapping is wrong or if this is a bug in Hibernate. I use the following mapping with a bidirectional one-to-many/many-to-one association.

Code:
    <class name="Facet">
        <id name="identifier" access="property"/>
        <property name="description" access="field"/>
        <property name="justOnce" access="property"/>
        <set name="taxonomies" access="property" sort="natural" cascade="all" lazy="false" inverse="true">
            <key column="identifier"/>
            <one-to-many class="Taxonomy"/>
        </set>
    </class>

    <class name="Taxonomy">
        <id name="identifier" access="property"/>
        <property name="description" access="property"/>
        <many-to-one name="facet" access="property" cascade="none" lazy="false"/>
    </class>


I use Apache Derby for testing and let Hibernate generate the structure on start-up.
What I get is the following DDL for the Taxonomy class.

Code:
CREATE TABLE TAXONOMY (
      IDENTIFIER INTEGER NOT NULL,
      DESCRIPTION VARCHAR(255),
      FACET INTEGER
   );
CREATE UNIQUE INDEX SQL080227005945580 ON TAXONOMY (IDENTIFIER ASC);
CREATE INDEX SQL080227005949500 ON TAXONOMY (FACET ASC);
CREATE UNIQUE INDEX SQL080227005949760 ON TAXONOMY (IDENTIFIER ASC);
ALTER TABLE TAXONOMY ADD CONSTRAINT SQL080227005945580 PRIMARY KEY (IDENTIFIER);
ALTER TABLE TAXONOMY ADD CONSTRAINT FKF43497719BC9F927 FOREIGN KEY (FACET)
   REFERENCES FACET (IDENTIFIER);
ALTER TABLE TAXONOMY ADD CONSTRAINT FKF43497713587B019 FOREIGN KEY (IDENTIFIER)
   REFERENCES FACET (IDENTIFIER);


As you can see there are two foreign keys generated, but the second (with the name FKF43497713587B019') is obviously wrong and should not (must not!!!) be there. It leads to foreign key violations on inserting.

Can someone please give me a helping hand?? Do I have to change the mapping??
Thank you


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

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.