Hi,

I would like to create a mapping for the following domain object.

class Person {
 private Person employer;
 private Set<Person> employees;

 public void addEmployee(Person employee) {
    employee.setEmployer(this);
    this.employees.add(employee);
 }

 public void setEmployer(Person employer) {
    this.employer = employer;
 }
}

Each person has one employer and many employees. The relationship is bi-directional as you can see from the code above. The bi-directional relationship is managed by method Person#addEmployee. You can see that when add an employee to a person will in turns set the employee's employer automatically.

The problem here is that, when using JiBX library to construct objects from XML file, the standard mapping approach does not use Person#addEmployee method, but it map class members directly. The XML file using is look like this:

<person>
 <name>James Clark</name>
 <employees>
    <person>
       <name>James Iha</name>
    </person>
    <person>
       <name>James Brown</name>
    </person>
 </employees>
</person>

From the XML file, there is no element to be mapped to Person#employer field. Therefore, when construct objects from XML file, all employer reference in each Person object are gone.

So here is the question, how can I maintain the reference in Person#employer field when unmarshalling from XML?

Regards,

--
Vairoj Arunyaangkul
Infowave (Thailand) Co., Ltd.
[EMAIL PROTECTED]
Tel: +66.2.654.3550
Fax: +66.2.654.3555
http://www.waveman.com




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to