I assume the decision point here is id values whose type is immutable internally? If so, we have a method for this already that I would prefer for this fix to use: org.hibernate.type.Type#isMutable.
Not really. The decision point is here the proper implementation of the #equals()-method of the id class. Take look at the loop at the end of the AbstractPersistenCollection#getOrphans. In the line 1148 you call the #contains()-method on a list. The #contains()-method uses the #equals()-method to compare objects. For the types selected in the #mayUseIdDirect()-method we can guarantee that the #equals()-method compares ids using their content and not something else. Type#isMutable does not tell us how the #equals()-method is implemented in the id class. If you change the specification of the Type#isMutable-method (incl. UserType and CompositeUserType) and define that the developer must provide a proper implementation of #equals-method in his id class, when Type#isMutable returns false, and you validate this contract when building session factory, then we can change the implementation and use Type#isMutable instead. Thus, the main purpose of the patch is to help existing applications, yet not to break anything. 
I'd make this change, but I am having a lot of trouble working your Pull Requests from the command line (which is how I normally like to work Pull Requests).
Not sure what problems you have, but according to the GitHub site of the pull request:
https://github.com/hibernate/hibernate-orm/pull/849
it can can be merged without any problem.
|