Hi,
we have a quite custom legacy solution migrating to Hiberate 6.5.0Final currently. So, maybe noone else will face this ClassCastException in CollectionEntry.postInitialize caused by casting to AbstractPersistentCollection in line
final SharedSessionContractImplementor session = ((AbstractPersistentCollection<?>)collection).getSession();
Why do we face this issue? Our custom collection class implements PersistentCollection but can not extend AbstractPersistentCollection.
Basically a possible solution to overcome this ClassCastException and having a cleaner casting to the interface type instead of casting to an abstract class can be achieved by extending PersistentCollection by a default method:
default SharedSessionContractImplementor getSession() {
return null;
}
So the cast to the abstract class can be replaced by casting to the interface type PersistentCollection:
final SharedSessionContractImplementor session = ((PersistentCollection<?>)collection).getSession();
Happy to hear from you if this might be considered as an improvement.