-->
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.  [ 7 posts ] 
Author Message
 Post subject: Maps and foreign key references
PostPosted: Sun Feb 24, 2008 12:28 am 
Newbie

Joined: Sat Nov 10, 2007 7:19 pm
Posts: 10
Hi,

I'm having a problem figuring this error message out.

Foreign key (FK3C7A6DB3B11727E9:inventory_item_map [inventory_number])) must have same number of columns as the referenced primary key (inventory [user_number,idx])

I understand that the foreign key needs to reference the same as the primary key.

The primary key is not composite, just one column, so I don't know why I get this message at all.

I have a similiar map and that one works fine, but not this table for some reason. They are identical except for table name in the database.

here is what i'm trying to do,

<map name="inventoryItems" table="inventory_item_map">
<key column="inventory_number"/>
<map-key-many-to-many column="item_number" class="com.inifim.commerce.data.Item"/>
<element type="integer" column="quantity"/>
</map>

Thanks,
Jay


Top
 Profile  
 
 Post subject: Re: Maps and foreign key references
PostPosted: Sun Feb 24, 2008 5:39 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
I'd guess Hibernate thinks the primary key in the inventory table consists of two columns: inventory [user_number,idx]

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 10:26 am 
Newbie

Joined: Sat Nov 10, 2007 7:19 pm
Posts: 10
Right, that's what I think as well.

But the primary key reference consists of only one column.

So I am at a loss as to why.

I'm not sure what idx is, possibly postgresql's index?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 3:06 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
How about posting class and mapping for "inventory"?

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 11:11 pm 
Newbie

Joined: Sat Nov 10, 2007 7:19 pm
Posts: 10
That's a good idea.

<hibernate-mapping>
<class name="InventoryManager" table="inventory">
<id name="inventory_number" column="inventory_number">
<generator class="increment"/>
</id>
<map name="inventoryItems" table="inventory_item_map">
<key column="inventory_number"/>
<map-key-many-to-many column="item_number" class="Item"/>
<element type="integer" column="quantity"/>
</map>
<one-to-one name="owner" class="User"/>
</class>
</hibernate-mapping>

create table inventory(
inventory_number bigint,
user_number bigint,
primary key(inventory_number),
foreign key(user_number) references users(id)
);

create table inventory_item_map(
inventory_number bigint,
item_number bigint,
quantity int,
primary key(inventory_number,item_number),
foreign key(inventory_number) references inventory(inventory_number),
foreign key(item_number) references item(item_number)
);

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 3:50 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Something is seriously messed up.

The primary key of inventory should be inventory_number, but the error message mentiones user_number and idx

So here is what I would do:

- post the inventoryManager class

- search the complete source code for user_number and idx

- create a small but complete testcase, reducing it until there is only the problem left.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 12:02 am 
Newbie

Joined: Sat Nov 10, 2007 7:19 pm
Posts: 10
OKay. I'll try that.

Do you think it could be a circular foreign key problem or something strange?

I have the same tables and mapping for a different class. It works just fine, I really can't see the difference between this and that.

Thanks.


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