Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.4, 1.4.1
-
Fix Version/s: 1.4.2
-
Component/s: Converters
-
Labels:None
-
JDK version and platform:Sun/Oracle 1.6.0_24 for Windows, 64bit
Description
A ClassCastException occurs when using a sorted map or sorted set with Hibernate and the XStream Hibernate extension package. The exception happens as an attempt is made to cast org.hibernate.collection.PersistentSortedSet to java.util.TreeSet or to cast org.hibernate.collection.PersistentSortedMap to java.util.TreeMap.
The Hibernate collection classes }} and {{ do not inherit from TreeSet or TreeMap; they use them internally as a backing store only.
The fix and work around for the problem is to wrap the PersistentSortedSet into a TreeSet and PersistentSortedMap into a TreeMap. This allows the super classes of HibernatePersistentSortedSetConverter and TreeMapConverter to perform the proper cast.
I attached a test class that demonstrates the problem, as well as the proposed solution.
I forgot to mention that the used Hibernate version was 3.6.5-Final.