When you have following mapping:
Code:
<set
name="products"
lazy="false"
table="category2product"
sort="natural"
node="products"
embed-xml="true">
<key column="categoryId"/>
<many-to-many class="Product" column="productId" embed-xml="true" node="product" />
</set>
and try when you try to fetch it as XML:
Code:
Session dom4jSession = session.openSession(EntityMode.DOM4J);
List results = dom4jSession.createQuery("from Category").list();
it you will get:
Code:
java.lang.ClassCastException: org.dom4j.tree.DefaultElement
at java.util.TreeMap.compare(TreeMap.java:1085)
at java.util.TreeMap.put(TreeMap.java:463)
at java.util.TreeSet.add(TreeSet.java:209)
at java.util.AbstractCollection.addAll(AbstractCollection.java:319)
at java.util.TreeSet.addAll(TreeSet.java:255)
at org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:237)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:170)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:244)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:227)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:458)
at org.hibernate.loader.Loader.doQuery(Loader.java:406)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1344)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:101)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:484)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1346)
at org.hibernate.type.CollectionType.getCollection(CollectionType.java:439)
at org.hibernate.type.CollectionType.resolve(CollectionType.java:296)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:452)
at org.hibernate.loader.Loader.doQuery(Loader.java:406)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
When you do eliminate the sort="natural" it works fine.
It seams to me that there is some bug in either comparator for tree set, of for compare function for elements that are added to the set.
Lukasz