Whoops - guess I should have tried compiling that before I posted it, eh? I changed the HashSet to an ArrayList and made some other modifications to your "Person" class so I could focus on the back-reference problem; I guess I forgot to unmake them before I copied the solution into my e-mail.
Anyway, what I was really trying to direct you to the post-set attribute; that will solve your problem of maintaining a "back reference" to the person's employer, which I believe was the question in your original post. I just ran a new compile using your original Person class, and a (simpler) collection mapping of: <collection name="employees" field="employees" usage="optional" /> And got your test.xml to unmarshal correctly using the unmodified (except for the addition of the postSet handler) Person class. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vairoj A. Sent: Friday, November 04, 2005 2:13 AM To: [email protected] Subject: [jibx-users] Re: Mapping bi-directional association Hi, I have tried adding 'add-method' attribute to the binding file as you suggested. However, I believe that the add-method specified here is the method for the collection. However, the addEmployee method resides in the Person class, not in the collection - in this case, HashSet class. So there is an error when running the binding compiler as follow: Error: add-method addEmployee not found in class java.util.HashSet for collection element at (line 43, col 5, in Campaign/jibx-binding.xml) Regards, Vairoj > Take a look at the "post-set" binding attribute > (http://jibx.sourceforge.net/tutorial/binding-extend.html): > > Add this to your binding file: > > <mapping name=3D"person" class=3D"com.package.Person" = > post-set=3D"postSet"> > <value name=3D"name" field=3D"name" /> > <collection name=3D"employees" add-method=3D"addEmployee" > item-type=3D"Person" usage=3D"optional" /> > </mapping> > > And this to Person: > public void postSet( IUnmarshallingContext ctx ) > { > if ( ctx.getStackDepth( ) > 1 ) > { > setEmployer( ( Person ) ctx.getStackObject( 1 ) ); > } > } > > The trick is to get at the unmarshalling context and go up one level in > the stack to the parent (but make sure to check the stack depth as shown > above and make sure that you're dealing with a collection element!). ------------------------------------------------------- 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 ------------------------------------------------------- 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
