-->
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: Many to Many mapping question - using JPA
PostPosted: Fri Jul 11, 2008 8:00 pm 
Newbie

Joined: Tue Oct 18, 2005 2:49 pm
Posts: 13
Hello,
Would appreciate any inputs on this.

I have 3 entity tables
A
a_id
name

B
b_id
name

U
u_id
name

and I jhave the foll association table
A-B association: many to many
A_B_MAP
a_b_id (pk)
a_id (fk)
b_id(fk)

some of you may be goin 'whoa' over here because of the completely unnecessary primary key. But this is not my call. DBA's insist on having a single column PK for every table.

and we have
U-A-B-MAP association table
U_ABMAP_MAP
u_abmap_id (pk)
u_id (fk)
a_b_id (fk)

U has a many to many association with a table that is a join table between A and B.

I have objects for all 3 entities ofcourse. And I also have an object for A_B_MAP to effect the U-A_B_MAP association.

A and B have a ManyToMany association, using A_B_MAP as the join table, with A being the owner (the direction itself is immaterial - problem occurs in all cases).
U has a collection of A_B_MAP and does a many to many on it using U_ABMAP_MAP as the join table.

the JPA Mappings are textbook. I can post these if you indeed think this is a mapping issue i.e incorrect annotations.

When I try to run my test I get:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/edmunds/identity/identity-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FKFB06A81645B9499C:U_ABMAP_MAP [A_B_ID])) must have same number of columns as the referenced primary key (A_B_MAP [A_ID,B_ID])

Why is hibernate trying to enforce this? It seems that it expects A_B_MAP to have a composite primary key inspite of the fact that the A_B_MAP object has an @Id annotation on a_b_id only.

I tried using this with toplink and it does not seem to have a problem with it.

thanks
Pratik


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.