-->
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: Foreign Key Problem
PostPosted: Thu Oct 13, 2005 1:13 pm 
Newbie

Joined: Wed Oct 12, 2005 2:50 pm
Posts: 11
Hibernate version: 3.05

Name and version of the database you are using: IBM DB2 v. 8.2

I am fairly new to Hibernate and I am trying to convert an existing application to use Hibernate for persistence. I am having difficulty with some of the mappings, so any help is greatly appreciated.

The Error I am getting is: SessionFactory creation failed.org.hibernate.MappingException: Repeated column in mapping for entity: software.executiveutilities.model.LinkInfo column: CATEGORY_ID (should be mapped with insert="false" update="false")

Here is the DDL:

CREATE TABLE APP.CATEGORIES
(ID INTEGER NOT NULL,
NAME VARCHAR(255) NOT NULL,
TEXT_AREA VARCHAR(10000)) in eutbspc2;

CREATE TABLE APP.FILES
(ID INTEGER NOT NULL,
NAME VARCHAR(255),
NUMBER_BYTES INTEGER,
BINARY_DATA BLOB(100M),
DATE_CREATED DATE,
NUMBER_DOWNLOADS INTEGER NOT NULL DEFAULT 0,
LAST_DOWNLOAD_DATE DATE) in eutbspc1;

ALTER TABLE APP.FILES
ADD CONSTRAINT "FILES_PK" PRIMARY KEY (ID);

CREATE TABLE APP.LINKS
(CATEGORY_ID INTEGER NOT NULL,
FILE_ID INTEGER NOT NULL,
NAME VARCHAR(255),
LINK_ORDER INTEGER);

ALTER TABLE APP.LINKS
ADD CONSTRAINT LINKS_PK PRIMARY KEY (CATEGORY_ID, FILE_ID);

ALTER TABLE APP.LINKS
ADD CONSTRAINT LINKS_FILE_FK FOREIGN KEY (FILE_ID)
REFERENCES APP.FILES(ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION;

ALTER TABLE APP.LINKS
ADD CONSTRAINT LINKS_CATEGORY_FK FOREIGN KEY (CATEGORY_ID)
REFERENCES APP.CATEGORIES(ID)
ON DELETE CASCADE
ON UPDATE NO ACTION;


Here are the mappings:

<class name="software.executiveutilities.model.Category" table="APP.CATEGORIES" lazy="false">

<id name="id" column="ID">
<generator class="increment" />
</id>
<list name="links" cascade="persist">
<key column="CATEGORY_ID" not-null="true"/>
<list-index column="LINK_ORDER" base="0" />
<one-to-many class="software.executiveutilities.model.LinkInfo" />
</list>
</class>


<class name="software.executiveutilities.model.LinkInfo" table="APP.LINKS" lazy="false">

<composite-id name="id" class="software.executiveutilities.model.LinkInfoId">
<key-property name="categoryId" type="int">
<column name="CATEGORY_ID" />
</key-property>
<key-property name="fileId" type="long">
<column name="FILE_ID" />
</key-property>
</composite-id>

<property name="name" column="NAME" />
<property name="order" column="LINK_ORDER" />

<many-to-one name="fileInfo" column="FILE_ID" unique="true" not-null="true" update="false" insert="false"/>
</class>

<class name="software.executiveutilities.model.FileInfo" table="APP.FILES" lazy="false">
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="filename" column="NAME"/>
<property name="fileSize" column="NUMBER_BYTES"/>
<property name="dateCreated" type="date" column="DATE_CREATED"/>
<property name="dateLastDownloaded" type="date" column="LAST_DOWNLOAD_DATE"/>
<property name="numberOfDownloads" column="NUMBER_DOWNLOADS"/>
<property name="fileData" type="blob" column="BINARY_DATA"/>
</class>

Any help is much appreciated. Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Foreign Key Problem
PostPosted: Thu Oct 13, 2005 1:29 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
rhombeus wrote:
column in mapping for entity: software.executiveutilities.model.LinkInfo column: CATEGORY_ID (should be mapped with insert="false" update="false")


So, uh, what happened when you put insert="false" and update="false" for CATEGORY_ID for LinkInfo?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 1:42 pm 
Newbie

Joined: Wed Oct 12, 2005 2:50 pm
Posts: 11
So where exactly do you suggest adding insert="false" and update="false" ? CATEGORY_ID is part of a composite id for LinkInfo and stored in a seperate id class called LinkInfoId. The LINKS table is a joining table between the CATEGORIES and FILES tables, but the LINKS table also maps to the LinkInfo objects which store the additional information (ie. other than the foreign keys).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 1:48 pm 
Newbie

Joined: Wed Oct 12, 2005 2:50 pm
Posts: 11
So where exactly do you suggest adding insert="false" and update="false" ? CATEGORY_ID is part of a composite id for LinkInfo and stored in a seperate id class called LinkInfoId. The LINKS table is a joining table between the CATEGORIES and FILES tables, but the LINKS table also maps to the LinkInfo objects which store the additional information (ie. other than the foreign keys).


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.