Hello,

You can achieve the functionality you need by using a kind of association class to hold the relationship between Folders.

You would create a class like

public class FolderRelation implements Serializable {

private int id;
private Folder parentFolder;
private Folder childFolder;

}

Then your Folder class becomes

public class Folder implements Serializable {

private String _title;
private ArrayList _bookmarkList;
private ArrayList _folderList; //<-- this will hold a bunch of FolderRelations instead of Folders

}

The mapping for FolderRelation looks something like

<class name="myapp.advanced.FolderRelation" identity="id">
<description>
This is an association class that allows folders to belong
to other folders (internal self relations).
</description>
<map-to table="folder_relation" xml="folder_relation" />
<field name="id" type="integer">
<sql name="id" type="integer"/>
<xml/>
</field>
<field name="childFolder"
type="Folder"
required="true">
<sql name="child_folder_title" />
<xml />
</field>
<field name="parentFolder"
type="myapp.advanced.Folder"
required="true">
<sql name="parent_folder_title" />
<xml />
</field>
</class>

You just need to change the mapping for Folders to hold an arraylist of FolderRelations.

I hope I have understood your problem correctly and that this helps.

Patrick

Luc Dewavrin wrote:

Hi,
i am pretty new to castor JDO, and i would like to
know if it is possible to persist recursive objects to database using
castor JDO.

Let me explain,
i have 3 objects XBEL, FOLDER and BOOKMARK.
Here is a description of the first two:

public class Xbel implements java.io.Serializable {

private Info _info;
private java.util.ArrayList _folderList;
...
}

public class Folder implements java.io.Serializable {

private java.lang.String _title;
private java.util.ArrayList _bookmarkList;
private java.util.ArrayList _folderList;
...
}

As you can see, Folder object has a list of Folder in its attributes =>
i have a tree structure with Xbel being the root node, bookmark being a leaf
and folder
being a node.

I guess i could design a database with a Node table
like Node ( id,father_id,type) to store relations between folders and
bookmarks +
folder and bookmark tables just storing information (title, info, etc...)
without any relation information.
But i won't be able to persist my objects with such a database schema with
Castor.

How can i store such objects in database? I also guess i could marshall
objects to an xml string
and store that xml string to database as xml is fine to represent a tree
structure . But i don't want
that kind of solution, just prefer to use castor JDO.

Any example would be appreciated.

Thanks,
Luc

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev

Reply via email to