More WOXML woes
So it’s time for yet another post on Apple’s WebObjects XML framework (or “WOXML” for short). We’ve both dealt with generating XML using a mapping model and without. When the XML generated are regarded as “documents”, we want them to be in a well-defined format. Then we want to make a “snapshot” and store it in a blob column, and in this case the format of the XML isn’t that important – and the fact that “uniquing” is handled automatically is more important.
But … to-one relationships aren’t handled very well. We’ve been trying lots of workarounds, but none of them have worked. Our final solution was to make all relationships to-many and “simulate” to-one relationships by doing this:
public void setCompany(Company company) {<br />
if (getCompany() != null) {<br />
removeFromInternalCompanies(getCompany());<br />
}<br />
if (company != null) {<br />
addToInternalCompanies(company);<br />
}<br />
}<br />
<br />
public Company getCompany() {<br />
if (getInternalCompanies() == null) return null;<br />
return (Company)getInternalCompanies().lastObject();<br />
}
You get the idea. This works for us. We’ve actually switched from to-one relationships, named them “internal” and added methods with the same signature as before, and things worked as before. Maltes tests confirms that this bug remains in WO5. (Check out the links to earlier posts in this entry.)