|
I have run into this issue recently and having put in some ugly hacks to compensate for this behaviour, I would also like to see some action to fix it. It also seems to be very timing dependent, as in my own scenarios it only happens about 10--15% of the times I run my app.
I would also like to add that this issue isn't solely a hashcode/equals problem. If you define the relationship with a @Sort to sort the collection (in my case a SortedSet with TreeSet implementation), then your comparator will inevitably fail in the same manner. You simply cannot sort a set of objects when none of the data is populated. In this case the instance is simply in an invalid state and should not be used in any manner. Unlike the hack I added for hashcode (if data is null, use id), I have no hack for the sorting problem.
Quite simply, calling methods on an instance before it is fully initialized is prone to error. In a typical java scenario, you would use an appropriate constructor, factory or builder pattern to prevent this from happening. As this is not possible in conjunction with Hibernate, it should still be possible to ensure that an instance won't be utilized until it is completely initialized.
|