-->
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.  [ 5 posts ] 
Author Message
 Post subject: Composite key containing a FK defined by a composite key
PostPosted: Mon Aug 23, 2004 9:33 am 
Newbie

Joined: Tue Aug 03, 2004 11:34 am
Posts: 8
Hi,
I'm trying to map a table having a composite key wich contains a foreign key on a table where the key is itself a composite key. Here is the mapping.

Code:
<hibernate-mapping>
    <class
        name="com.atronicsystems.database.data.OnlineCollectionSchedule"
        table="SCOLPLA"
        dynamic-update="false"
        dynamic-insert="false"
    >

<composite-id name="id"    class="com.atronicsystems.database.data.OnlineCollectionScheduleId"
>
                     <key-property
                        name="weekDay"
                        type="java.lang.Integer"
                        column="JOUR"
                        length="1"
                />

                    <key-many-to-one
                        name="onlineCollectionDescription"                                       class="com.atronicsystems.database.data.OnlineCollectionDescription"
                        column="onlineCollectionDescription"
                    />
</composite-id>
...
</hibernate-mapping>


<hibernate-mapping>
    <class
     name="com.atronicsystems.database.data.OnlineCollectionDescription"
        table="SCOLLEC"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <composite-id
            name="id"        class="com.atronicsystems.database.data.OnlineCollectionDescriptionId"
        >
                     <key-property
                        name="companyCode"
                        type="java.lang.String"
                        column="COD_SOCIET"
                />

                     <key-property
                        name="casinoCode"
                        type="java.lang.String"
                        column="COD_ETABLI"
                />

                     <key-property
                        name="collectIdentifier"
                        type="java.lang.Long"
                        column="ID_COLLECT"
                />

        </composite-id>
...
</hibernate-mapping>



The problem is that with this mapping i got the following error:

Code:
Error was
net.sf.hibernate.MappingException: Foreign key (SCOLPLA [COD_SOCIET])) must have same number of columns as the referenced primary key (SCOLLEC [COD_SOCIET,COD_ETABLI,ID_COLLECT])


It seems logic because OnlineCollectionDescription does not contains variables of many to one association.

But if i change the many-to-one association and i use an OnlineCollectionDescriptionId rather than a OnlineCollectionDescription class to map the FK. The error is :

Code:
An association from the table SCOLPLA refers to an unmapped class: com.atronicsystems.database.data.OnlineCollectionDescriptionId


So how can i define a composite key which contains a foreign key defined by itself by a composite key?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 3:55 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 3:27 pm
Posts: 21
It looks to me (although it's hard to tell without understanding your model) that you're missing defining the columns in the key-many-to-one, you need to define the same number of columns there as the other composite id defines.

i.e. you need something like this (substituting COLUMNX with the right names of course

Code:
            <key-many-to-one
                name="onlineCollectionDescription"
                class="com.atronicsystems.database.data.OnlineCollectionDescription"

                >
                <column
                    name="COLUMN1"
                    />
                <column
                    name="COLUMN2"
                    />
                <column
                    name="COLUMN3"
                    />
            </key-many-to-one>


Of course if you want to save yourself some grief and you can change the datamodel, you should avoid composite keys.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 9:25 am 
Newbie

Joined: Tue Aug 03, 2004 11:34 am
Posts: 8
You're right.

But i realize that the problem is in my xdoclet tags:

I'm using the following tags:
Code:
/**
     *                @hibernate.many-to-one
     *                 @hibernate.column name="COD_SOCIET"
     *                 @hibernate.column name="COD_ETABLI"
     *                 @hibernate.column name="ID_COLLECT"
     *             
     */
    public com.atronicsystems.database.data.OnlineCollectionDescription getOnlineCollectionDescription() {
        return this.onlineCollectionDescription;
    }

    public void setOnlineCollectionDescription(com.atronicsystems.database.data.OnlineCollectionDescription onlineCollectionDescription) {
        this.onlineCollectionDescription = onlineCollectionDescription;
    }


Which generate the following mapping :

Code:
<key-many-to-one
                        name="onlineCollectionDescription"
                        class="com.atronicsystems.database.data.OnlineCollectionDescription"
                        column="onlineCollectionDescription"
                    />


But i need the following:

Code:
<key-many-to-one
                        name="onlineCollectionDescription"                     class="com.atronicsystems.database.data.OnlineCollectionDescription"
                    >

<column name="COD_SOCIET" />
           <column name="COD_ETABLI" />
           <column name="ID_COLLECT" />
</key-many-to-one>


So what's wrong with my tags?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 11:02 am 
Beginner
Beginner

Joined: Tue Dec 09, 2003 3:27 pm
Posts: 21
I would recommend looking at http://opensource.atlassian.com/projects/xdoclet/browse/XDT-776 I'm not sure if this has been resolved in any form other than the patch I supplied.

See what I mean about avoiding composite keys? :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 6:33 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:32 pm
Posts: 36
Location: S
I


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