-->
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: Could someone please explain if this is One2One or One2Many?
PostPosted: Tue Aug 21, 2007 8:01 pm 
Newbie

Joined: Fri Feb 09, 2007 2:43 pm
Posts: 4
I have the following object model which represents a directory structure:
Code:
@Entity
@Table(name = "workspace_folders")
@AttributeOverride(name="id", column=@Column(name="path_id"))

public class DirectoryModel extends BaseModel implements Serializable {
   
   /* user to which the directory ownership belongs */
   private long user_id;
   
   /* is this directory a users root directory? */
   private Boolean root;
   
   private String name;
   private String description;

   @OneToOne(targetEntity = DirectoryModel.class, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
   @JoinTable(name = "workspace_folders_rel",
       joinColumns = {@JoinColumn(name = "path_id", referencedColumnName="path_id")},
       inverseJoinColumns = @JoinColumn(name = "parent_id")
   )
   private DirectoryModel parent;
   
   @OneToMany(targetEntity = DirectoryModel.class, fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
   @JoinTable(name = "workspace_folders_rel", joinColumns = {@JoinColumn(name = "parent_id", referencedColumnName = "path_id")}, inverseJoinColumns = {@JoinColumn(name = "path_id")})
   private List<DirectoryModel> folders = new ArrayList<DirectoryModel>();
   
   @OneToMany(targetEntity = FileModel.class, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
   @JoinTable(name = "workspace_file_folder_rel", joinColumns = {@JoinColumn(name = "path_id", referencedColumnName = "path_id")}, inverseJoinColumns = {@JoinColumn(name = "file_id")})
   private List<FileModel> files = new ArrayList<FileModel>();
   
   // GETTERS AND SETTERS BELOW


the folders and files collections maintain all the sub-folders and files within the current active Model. These collections work perfectly!

My issue is with the declaration here:
Code:
@OneToOne(targetEntity = DirectoryModel.class, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
   @JoinTable(name = "workspace_folders_rel",
       joinColumns = {@JoinColumn(name = "path_id", referencedColumnName="path_id")},
       inverseJoinColumns = @JoinColumn(name = "parent_id")
   )
   private DirectoryModel parent;


I am trying to keep a direct reference to the PARENT DirectoryModel of this folder (ie. current DirectoryModel is a sub-directory of which PARENT DirectoryModel.) the parent var can obviously be null (this would imply it is a root folder.)

The two Database tables that are of issue are defined as follows:

workspace_folders:
Code:
path_id         bigint(20) unsigned   NO   PRI   NULL   auto_increment
user_id         bigint(20) unsigned   NO         
name        varchar(200)            NO          root   
description  varchar(255)           YES         NULL   
root           tinyint(4)                  NO        0


workspace_folders_rel:
Code:
path_id         bigint(11) unsigned   YES      NULL   
parent_id    bigint(11) unsigned       YES          NULL


I believe it is a OneToOne relationship to obtain my 'parent' var since every DirectoryModel can have at most ONE parent DirectoryModel.

On the flipside tough, a parent DirectoryModel can have multiple sub-DirectoryModels (technically represented by the folders Collection.)

I know I'm overly confusing myself here but could anyone please provide some insight as to where I might be going wrong in my mapping on the
DirectoryModel parent variable?

At present MyEclipse doesn't like the OneToOne mapping saying: "the join column parent_null cannot be found on the table workspace_folders"

I suppose this has someting to do with the parent_id column not being part of workspace_folders but don't see where my mapping is incorrect?

Thanks so much to anyone who might offer some insight!

Regards,
Skoal

[/code]


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.