Hibernate version: 3.2.4
Using a UserCollectionType - all is working great! Except I just want to check how to initialize it with arbitrary properties.
In the non-persistent case, if I wanted the collection to have a reference back to the parent I would just do something like:
Code:
public class MyClass {
IMyCollection mycoll = new MyCollection(this);
}
In the persistent case, though, that line doesn't actually instantiate the MyCollection instance - it's instantiated at some later time by the persister calling the UserCollectionType subclass, neither of which has a reference to the MyClass instance.
So here's what I've done:
1. Added a setMyClass method to the IMyCollection interface
2. Added a MyClass property to the persister. Note that setMyClass() in the persister can't just delegate to setMyClass() in the wrapped set, because the wrapped set might not yet be instantiated, so...
3. In the persister, overridden beforeInitialize() to call set.setMyClass(...).
The idea being to set properties on the wrapped set after it has been instantiated but before it gets used.
The question is, is this the right place to be doing this? AbstractPersistentCollection.initialize() might seem more natural, but it's final.