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