-->
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: mapping self referencing class
PostPosted: Sun Jun 12, 2011 8:40 am 
Newbie

Joined: Sun Jun 12, 2011 8:31 am
Posts: 1
Hi

I'm new to Hibrenate and i'm having trouble mapping the following case (using annotations) :

I have a table holding a list of folders - each referencing a parent folder :

User_folders :
Folder_id integer,
Folder_name varchar2(30),
Parent_folder_id integer

Folder & Parent folder are of the same class.

I'm trying to create the following mapping :

In the UserFolder class - have the following :

private UserFolder getParentFolder(); - should return the parent folder of the current folder
private List<UserFolder> getChildFolders(); - should return a list of folders that their parent folder is the current folder

Here is the class :

@Entity
@Table(name = "user_folders")
public class UserFolder extends Serializable {

// Members
private Integer userFolderId;
private UserFolder parentFolder;
private List<UserFolder> folders = new ArrayList<UserFolder>();

// Folder id
public void setUserFolderId(Integer userFolderId) {
this.userFolderId = userFolderId;
}

@Id
@Column(name = "user_folder_id")
@GeneratedValue(generator = "hibseq")
@GenericGenerator(name = "hibseq", strategy = "seqhilo", parameters = { @Parameter(name = "sequence", value = "recipeDrawer.user_folder_id_seq") })
public Integer getUserFolderId() {
return userFolderId;
}

// List of inner folders
public void setFolders(List<UserFolder> folders) {
this.folders = folders;
}
public List<UserFolder> getFolders() {
return folders;
}

// Parent folder id
public void setParentFolder(UserFolder parentFolder) {
this.parentFolder = parentFolder;
}
public UserFolder getParentFolder() {
return parentFolder;
}


}

i've tried looking for such example - but couldn't find any that worked.

Will appreciate any help - or reference to a working example

Thanks
Inbal


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.