I've tried to make a directory listing persistent with Hibernate, meaning that one directory may have several subdirectories, each of them having subdirectories as well.
I have one class as well as one table which might look like this:
Code:
CREATE TABLE mydirectory (
id bigint(20) NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
parent_id bigint(20),
PRIMARY KEY (id),
KEY par (parent_id),
FOREIGN KEY (`parent_id`) REFERENCES `mydirectory` (`id`)
) TYPE=InnoDB;
Making the relationship bi-directional (see chapter 9 of reference manual) seems to work, but how about a uni-directional relationship?
Is this possible with hibernate and how would the mapping look like?
Unfortunately, I haven't found an examples concerning this topic...
Thanks for your help!