-->
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.  [ 3 posts ] 
Author Message
 Post subject: JPA - Foreign key must have same number of columns as..????
PostPosted: Mon Aug 20, 2007 1:35 pm 
Newbie

Joined: Fri Feb 09, 2007 2:43 pm
Posts: 4
I have the following declared in my DirectoryModel POJO Entity class.

Code:
@OneToMany(targetEntity = DirectoryModel.class, fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE})
@JoinTable(name = "workspace_folders", joinColumns = {@JoinColumn(name = "parent_id")}, inverseJoinColumns = {@JoinColumn(name = "path_id")})
private Set<DirectoryModel> folders = new HashSet<DirectoryModel>();

@OneToMany(targetEntity = FileModel.class, fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE})
@JoinTable(name = "workspace_file_folder_rel", joinColumns = {@JoinColumn(name = "path_id")}, inverseJoinColumns = {@JoinColumn(name = "file_id")})
private Set<FileModel> files = new HashSet<FileModel>();


folders contains all sub-folders of any given directory and files contains files in the given directory (imagine a very crude doc manager.)

When I convert the folders to a collection bag of List<DirectoryModel>
everything works fine! Now when I'm trying to use Set<DirectoryModel>
for the sub-folder collection I keep getting the following error when JBOSS boots up:

Code:
org.hibernate.MappingException: Foreign key (FK9E08F041A79D6EA:workspace_file_folder_rel [path_id])) must have same number of columns as the referenced primary key (workspace_folders [parent_id,path_id])


I have the following tables:

workspace_folders:
5 columns, single primary key (path_id)

workspace_files:
7 columns, single primary key (file_id)

workspace_file_folder_rel:
2 columns (path_id & file_id) as composite primary key

I've tried placing a surrogate primary key "rel_id" into workspace_file_folder_rel but I continue to get the same error.

Would anyone PLEASE see where I'm going wrong here? I haven't even declared any foreign keys anywhere that I am aware of.

Regards,
Skoal[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2007 4:39 pm 
Newbie

Joined: Fri Feb 09, 2007 2:43 pm
Posts: 4
I thought I might add that if I comment out either one of the OneToMany relationships and try to fire it up with just a single Set (either directories or folders) it seems to work fine.

What the heck?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 28, 2007 2:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Are you usre you don't use the same join table name for both relationships?

_________________
Emmanuel


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