The attached patch and org.castor.util.CycleBreaker class are sufficient for the test case but cause one basic CTF test to fail:
There was 1 failure:
1) sourcegenerator/Primitives/WithWrappers/Test when using wrapper objects instead of primitives#Test Marshaling with the generated Descriptors_ReferenceDocument(org.castor.xmlctf.TestWithReferenceDocument)junit.framework.AssertionFailedError: The initial reference object and the one resulting of the marshal/unmarshal process are different
Tests run: 304, Failures: 1, Errors: 0
I've not yet worked out quite where this is failing, but it is almost certainly due to the patched equals method behaving incorrectly. Hopefully someone more experienced than myself will spot the problem here.