I wonder if there is a way to have Castor properly handle backreferences.

For example: I have a Library that contains a list of Books but each book
also has a backreference to a Library it is contained at.
The problem I have is when it is persisted into XML the backreference is not
there.

Here are my 2 classes

public class Library
{
    List books = null;

    public List getBooks()
    {
        return this.books;
    }

    public void setBooks(List books)
    {
        this.books = books;
    }

    public Library()
    {
        super();
    }

}

public class Book
{
    private String title;
    private String author;
    private String price;
    private Library backpointer;

    public void setBackpointer(Library backpointer)
    {
        this.backpointer = backpointer;
    }

    public Library getBackpointer()
    {
        return this.backpointer;
    }

    public Book()
    {
        super();
    }

    public String getAuthor()
    {
        return this.author;
    }

    public void setAuthor(String author)
    {
        this.author = author;
    }

......................the rest of getters and setters
}



The XML generated is

<library>
    <books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:type="java:test.dima.Book">
        <author>aaa</author>
        <price>3</price>
        <title>rrr</title>
    </books>
    <books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:type="java:test.dima.Book">
        <author>aaa2</author>
        <price>32</price>
        <title>rrr2</title>
    </books>
</library>



As you can see under <book> node there is no backreference to Library. Is
there special way I can configure mapping to accomplish this?

Reply via email to