I have the following collection:
> ...
> <bag name="comments" table="CR_COMMENT" order-by="CREATE_TS asc">
> <key column="REQ_ID" />
> <composite-element class="Comment">
> <property name="createTs" column="CREATED_DATE"
> type="calendar" access="field"
> update="false" insert="false"
> generated="always" />
> <property name="sectionId" column="SECTION_ID" />
> <property name="userId" column="USER_ID" />
> <property name="text" column="TEXT"/>
> </composite-element>
> </bag>
> ...
defined in the Java class as
> private Collection comments = new ArrayList();
because all the examples in JPH show bags implemented as
Collection interfaces backed by ArrayLists. At runtime I
get:
08:43:42,598 ERROR org.hibernate.property.BasicPropertyAccessor:94 -
IllegalArgumentException in class: om.wholefoods.ittoolkit.ws.ccf.Request,
setter method of property: comments
08:43:42,598 ERROR org.hibernate.property.BasicPropertyAccessor:98 -
expected type: java.util.SortedSet, actual value:
org.hibernate.collection.PersistentBag
This makes sense, because the order-by attribute implies that
some sort of ordered iterator will be required. However, won't
substituting a SortedSet for the ArrayList will cause the
collection to use Set semantics (no duplicate) instead of
"bag" semantics (duplicates allowed)?
Or, does Hibernate do something under the covers to preserve
the bag semantics?
Jim Garrison - 12 Mar 2007 16:03 GMT
Curiously, if I replace the implementation with a TreeSet,
I still get exactly the same error from Hibernate.
What's the secret to using "order-by" with a <bag>
collection?