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: FKs Mapping for Compisite PKs
PostPosted: Thu Feb 25, 2010 3:55 pm 
Newbie

Joined: Thu Feb 25, 2010 3:48 pm
Posts: 2
Hi, I'm facing a big problem here and tried a lot to find the answers in the Internet but not succeeded...

I have tables where two of them have a composite PK, and the third one has two FKs point for those two PKs...
Here is the ALTER TABLE that creates the FKs

Code:
ALTER TABLE FIELD ADD CONSTRAINT FK_FIELD_DEF FOREIGN KEY (ENTITY_TYPE_NAME, FIELD_DEF_NAME) REFERENCES FIELD_DEF (ENTITY_TYPE_NAME, NAME);
ALTER TABLE FIELD ADD CONSTRAINT FK_ENTITY_MAPPING_2 FOREIGN KEY (ENTITY_TYPE_NAME, ENTITY_MAPPING_NAME) REFERENCES ENTITY_MAPPING (ENTITY_TYPE_NAME, NAME);


The problem is that one of the composite PKs fields is the same for both tables... How can I map it on Hibernate? The field table is:
Code:
CREATE TABLE FIELD (
  POSITION NUMBER(4) NOT NULL,
  USER_FORMAT VARCHAR(100) NOT NULL,
  ENTITY_TYPE_NAME VARCHAR(100) NOT NULL,
  FIELD_DEF_NAME VARCHAR(100) NOT NULL,
  ENTITY_MAPPING_NAME VARCHAR(100) NOT NULL,
  CONSTRAINT PK_FIELD PRIMARY KEY (ENTITY_TYPE_NAME, FIELD_DEF_NAME, ENTITY_MAPPING_NAME)
);


And my mapping file is:
Code:
<class ...>
<composite-id>       
       <key-many-to-one name="entityMapping" class="com.model.EntityMapping">
                 <column name="ENTITY_MAPPING_NAME" />
                 <column name="ENTITY_TYPE_NAME" />
              </key-many-to-one>
              <key-many-to-one name="fieldDef" class="com.model.FieldDef">
                 <column name="ENTITY_FIELD_NAME" />
                 <column name="ENTITY_TYPE_NAME" />
              </key-many-to-one>     
           
          </composite-id>
         <property name="position" access="field" />
         <property name="userFormat" access="field" column="USER_FORMAT" />
   </class>


Which returns an error:
Repeated column in mapping for entity

Thanks.


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.