I failed with this easy directory/folder example, because I don't know how to write the mapping if
first level folders of the directory
have the root as parent and
all other folders have a folder as parent.
So the data-structure ist the same as you know it from a directory.
There are 2 objects to persist:
- the directory-root, which contains folders (all folders without a parentFolder)
- folders, which can contain other folders
The
table Folders looks like this:
Code:
ID_Folder, ID_Parent_Folder, Name
If a folder has no parentFolder it is child of the root-object.
This is the
mapping for the Collection-Set "childFolders" of a Folder :
Code:
<set name="childFolders" cascade="all" lazy="false">
<key column="ID_PARENT_FOLDER"/>
<one-to-many class="Folder"/>
</set>
But I don't know how to write the mapping for the childFolders of the root?
Because therefor I would have to select all folders which don't have a parentfolder.
Can you please help me?