Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2007

Tip: Looking for answers? Try searching our database.

[Hibernate] "order-by" attribute on <bag> requires SortedSet implementation?

Thread view: 
Jim Garrison - 12 Mar 2007 15:56 GMT
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?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.