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]